<?php
if( !defined('IN') ) die('bad request');
include_once( AROOT . 'controller'.DS.'app.class.php' );

class defaultController extends appController
{
	function __construct()
	{
		parent::__construct();
		if( g('a') != 'login' && g('a')!="oauth" && g('a')!='authorize' && g('a')!='token' && g('a') != 'login_check' && g('a') != 'register' && g('a') != 'showcaptcha' && g('a') != 'doreg' && g('a') != 'vemail' && g('a') != 'doactive'&& g('a') != 'active'&& g('a') != 'reactive' && g('a') !='resetpwd' && g('a') !='resetpwd_mail' && g('a') !='doresetpwd' && g('a') !='newpwd' && g('a')!='iewarning' && g('a')!='check_qrcode' && g('a')!='download_file' && g('a')!='sign_confirmation' && g('a')!='fund_ticket_singed_in' && g('a')!='ticket_signed' && g('a')!='refresh' && g('a')!='history_fund_active' && g('a')!='history_name_check' && g('a')!='history_email_active' &&g('a')!='init_pwd' && g('a')!='doinitpwd')
		{
			if( !is_login() )
			{
				ajax_echo("<script>location = '/?a=login';</script>");
				exit();
			}
		}
		session_start();
	}

	private function getEdudataInstance($email=NULL,$password=NULL)
	{
		return parent::getEdudata($email,$password);
	}
	
	private function init_generaldata()
	{
		$edudata = self::getEdudataInstance();
		if($_SESSION['department']==""||$_SESSION['nation']==""||$_SESSION['native_place']=="")
		{

			$general = $edudata->general_data();
			if($general['err_code']=='0')
			{
				$_SESSION['department'] = $general['data']['department'];
				$_SESSION['nation'] = $general['data']['nation'];
				$_SESSION['native_place'] = $general['data']['native_place'];
			}else{
				ajax_echo("API错误，无法获取通用数据<script>location='/?a=refresh';</script>");
			}
		}

		//stage那里需要刷新，每次取也行
		// if($_SESSION['qlty_project_category']=="")
		// {
		$qlty_options=$edudata->get_qlty_option();
		if($qlty_options!==FALSE){
			foreach($qlty_options as $qlty_option)
			{
				$_SESSION[$qlty_option['qlty_option_name']]=$qlty_option['qlty_option_value'];
			}
		// }
		}

	}

	public function refresh()
	{
		//这部分非常有必要在登陆处“重置登陆缓存”
		// echo "access_token:  ";
		/*var_dump($_COOKIE['atk'.$_SESSION['teacher']['teacher_id']]);
		echo "refresh_token:  ";
		var_dump($_COOKIE['rtk'.$_SESSION['teacher']['teacher_id']]);*/
		if (isset($_SERVER['HTTP_COOKIE'])) {
			$cookies = explode(';', $_SERVER['HTTP_COOKIE']);
			foreach($cookies as $cookie) {
				$parts = explode('=', $cookie);
				$name = trim($parts[0]);
				setcookie($name, '', time()-12096000);
				setcookie($name, '', time()-12096000, '/');
			}
		}
		
		echo "<span class='label label-important'>已更新缓存……请重新授权登陆</span>";
		//exit();
	}

	public function index()
	{
		//$qlty_asset_type=Array("11"=>"申报书WORD","12"=>"申报书PDF","21"=>"任务书WORD","22"=>"任务书PDF","31"=>"开题报告WORD","32"=>"开题报告PDF","41"=>"中期检查报告WORD","42"=>"中期检查PDF","51"=>"项目变更报告WORD","52"=>"项目变更报告PDF","61"=>"结题报告WORD","62"=>"结题报告PDF");
		//$data['qlty_asset_type']=$qlty_asset_type;

		//获取department、nation、native_place
		self::init_generaldata();

		$tid=$_SESSION['teacher']['teacher_id'];
		$qlty_current_stage=unserialize(ss('qlty_current_stage'));

		$edudata = self::getEdudataInstance();
		$user_projects=NULL;
		$user_projects = $edudata->get_user_projects($tid);
		//var_dump($user_projects);
		$projects=Array();
		if(is_array($user_projects)){
		foreach($user_projects as $user_project)
		{
			//获取该项目所属类型的阶段值
			$current_stage_num=$qlty_current_stage[$user_project['type']]['current_stage'];
			$current_stage_stages=$qlty_current_stage[$user_project['type']]['stages'];
			
			/*这里面需要处理每个项目，初始检查是否设置好了参与人，上传好了申报书；后面再根据阶段判断，给予不同的ac（给按钮）
			*current_stage
			*participants
			*assets
			*/
			//用户按钮
			$actions=Array();
			$participants=Array();
			$participants = $edudata->get_project_participants($user_project['qlty_project_id']);
			//取出assets
			$qlty_asset_status = $edudata->get_qlty_asset_status($user_project['qlty_project_id'],$tid);
			
			if($user_project['status']<$GLOBALS['project_status']['APPLYFILE'])
			{

				//如果已经过了申报期，禁止操作
				if(time()>strtotime($current_stage_stages['10']['end'])){
					$actions['text']="此轮项目申报期已过，项目未申报";
					$actions['ac']="javascript:void(0)";
				}else{

					//还在申报期内
					/************************项目初始化检查***********************************************************/
					/********************************Step1*******************************************/
					//1 无参与人则需要添加参与人
					$actions['editable']=0;
					$actions['edit_url']="/?a=edit_project&pid=".$user_project['qlty_project_id']."&tid=".$tid;

					if(!$participants){
						$actions['text']="请点击此按钮添加项目参与人";
						$actions['ac']="show_float_box('/?a=participants&pid=".$user_project['qlty_project_id']."&tid=".$tid."','设置参与人')";
					}else{
						//若设置了参与人
						//更新项目状态为 PARTICIPANT
						if($user_project['status']<$GLOBALS['project_status']['PARTICIPANT'])
							$result=$edudata->update_project_status($user_project['qlty_project_id'],$tid,$GLOBALS['project_status']['PARTICIPANT']);

						/********************************Step2*******************************************/
						//2 然后检查是否有申报书
						
						//上传完成标识
						$apply_file=0;
						
						if($qlty_asset_status!=FALSE)
						{
							//检查申报书word（11）与申报书PDF（12）是否上传，分别反馈
								foreach($qlty_asset_status as $qs)
								{

									//只要有未上传的，就显示上传文件按钮
									if( $qs['asset_type']=='11' && $qs['asset_uri']!="")
									{
										$apply_file=$apply_file+1;
									}
									if($qs['asset_type']=='12' && $qs['asset_uri']!="")
									{
										$apply_file=$apply_file+1;
									}
									if( $qs['asset_type']=='13' && $qs['asset_uri']!="")
									{
										$apply_file=$apply_file+1;
									}
									if($qs['asset_type']=='14' && $qs['asset_uri']!="")
									{
										$apply_file=$apply_file+1;
									}
								}
						}else{
							//info_page('获取数据出错，请稍后访问!');
						}//qlty_asset_status-->
						//注意，现在只要求1个word上传
						$file_num=1;
						if($apply_file!=1){
							$actions['text']="请点击此按钮上传全部申报材料";
							$actions['ac']="javascript:location='/?a=upload&file=1&qltyid=".$user_project['qlty_project_id']."&se=".md5("fp".$user_project['qlty_project_id']."s")."'";
						}else{
							//说明status未更新，将其更新为APPLYFILE
							$result=$edudata->update_project_status($user_project['qlty_project_id'],$tid,$GLOBALS['project_status']['APPLYFILE']);
							if($result)
							{
								return ajax_echo("<script>location='/?a=refresh_and_redirect_index'</script>");
							}
						}
					}//if $participants-->

				}//--->申报期时间检查
			/******************************************************************************/
			//项目状态初始化完成（参与人设置好了，申报书上传完成）
			/********************************************************************************/
			}else{
				$time=time();
				switch($user_project['status'])
				{
					case $GLOBALS['project_status']['APPLYFILE']:

						$actions['editable']=1;
						
						if($current_stage_num=='10' && $time>strtotime($current_stage_stages['10']['begin']) && $time<strtotime($current_stage_stages['10']['end']) )
						{
							//申报阶段,可提交
							$actions['text']="等待部门负责人审核推荐";
							//$actions['ac']="show_float_box('/?a=xmkverify&pid=".$user_project['qlty_project_id']."&tid=".$tid."','确认提交初审')";
							$actions['ac']="javascript:void(0)";
							$actions['green']=0;
						}else{
							//此项目没有提交，既可以随意修改
							$actions['text']="修改项目信息";
							$actions['ac']="javascript:location='/?a=edit_project&pid=".$user_project['qlty_project_id']."&tid=".$tid."','修改项目信息'";
							$actions['green']=0;
						}

						break;				
					case $GLOBALS['project_status']['WAITING_FOR_VERIFY']:
						if($current_stage_num=='20' && $time>strtotime($current_stage_stages['20']['begin']) && $time<strtotime($current_stage_stages['20']['end']))
						{
							$actions['text']="项目科初审中，请耐心等待……";
							$actions['ac']="javascript:void(0)";
							$actions['green']=2;
						}else{
							/*$actions['text']="取消初审提交";
							$actions['ac']="show_float_box('/?a=abandverify&pid=".$user_project['qlty_project_id']."&tid=".$tid."','取消提交初审')";*/
							$actions['text']="尚未开始初审，请耐心等待……";
							$actions['ac']="javascript:void(0);";
							$actions['green']=1;
						}
						break;

					case $GLOBALS['project_status']['REJECTED']:
						//本年度
						if(date('Y',time())==date('Y',strtotime($current_stage_stages['20']['begin'])) &&$current_stage_num=='20' && $time>strtotime($current_stage_stages['20']['begin']) && $time<strtotime($current_stage_stages['20']['end']))
						{
							$actions['editable']=1;
							$actions['edit_url']="/?a=edit_project&pid=".$user_project['qlty_project_id']."&tid=".$tid;
							$actions['text']="初审被驳回，请按要求修改项目信息后重新提交";
							$actions['ac']="javascript:location='/?a=edit_project&pid=".$user_project['qlty_project_id']."&tid=".$tid."'";
							$actions['green']=2;

						}else{
							//若为立项评审，则提示查看评审意见
							if($current_stage_num=='30')
							{
								// $actions['text']="对不起，项目立项失败，请点击查看评审结果";
								// $actions['ac']="javascript:location='/?a=teacher_result&pid=".$user_project['qlty_project_id']."&tid=".$tid."'";

								//不反馈意见
								$actions['text']="项目立项失败，点击查看评审意见";
								$actions['ac']="javascript:location='/?a=teacher_result&pid=".$user_project['qlty_project_id']."&tid=".$tid."'";
								$actions['green']=0;
							}else{
								$actions['text']="项目立项失败，点击查看评审意见";
								$actions['ac']="javascript:location='/?a=teacher_result&pid=".$user_project['qlty_project_id']."&tid=".$tid."'";
								$actions['green']=0;
							}

						}
						break;

					case $GLOBALS['project_status']['FIRST_TRIAL']:
						if($current_stage_num=='30')
						{
							$actions['text']="项目立项评审中……";
							$actions['ac']="javascript:void(0)";
							$actions['green']=4;
						}else{
							$actions['text']="项目通过初审，等待立项评审";
							$actions['ac']="javascript:void(0)";
							$actions['green']=3;
						}
						break;

					case $GLOBALS['project_status']['ESTABLISHED']:
						// if($current_stage_num=='30')
						// {
						// 	if($time>strtotime($current_stage_stages['30']['begin']) && $time<strtotime($current_stage_stages['30']['end']))
						// 	{
						// 		$actions['text']="恭喜，项目立项成功，点击查看评审结果";
						// 		$actions['ac']="javascript:location='/?a=teacher_result&pid=".$user_project['qlty_project_id']."&tid=".$tid."'";
						// 		$actions['green']=4;			
						// 	}else{
						// 		$actions['text']="请根据专家反馈意见提交任务书";
						// 		$actions['ac']="javascript:location='/?a=upload&file=2&qltyid=".$user_project['qlty_project_id']."&se=".md5("fp".$user_project['qlty_project_id']."s")."'";
						// 		$actions['green']=4;
						// 	}

							
						// }else{
						// 	$actions['text']="项目已立项，请抓紧建设";
						// 	$actions['ac']="javascript:void(0)";
						// 	$actions['green']=4;
						// }
								$actions['text']="请根据专家反馈意见提交任务书";
								$actions['ac']="javascript:location='/?a=upload&file=2&qltyid=".$user_project['qlty_project_id']."&se=".md5("fp".$user_project['qlty_project_id']."s")."'";
								$actions['green']=4;
						break;
					case $GLOBALS['project_status']['WAITING_FOR_UPGRADE']:
								//如果是升级为市级
								if($user_project['rank']==2)
								{
									$actions['text']="您的项目拟被推荐为市级项目，请提交市级项目申报书";
								}else{
									$actions['text']="您的项目级别与初始申报时发生更改，请修改并提交项目申报书";
								}
								$actions['ac']="javascript:location='/?a=upload&file=1&qltyid=".$user_project['qlty_project_id']."&se=".md5("fp".$user_project['qlty_project_id']."s")."'";
								$actions['green']=4;
								$actions['editable']=1;
						break;


					case $GLOBALS['project_status']['CHANGING']:
						$actions['text']="项目调整中，请点击此按钮确认上传调整申请单";
						$actions['ac']="javascript:location='/?a=upload&file=5&qltyid=".$user_project['qlty_project_id']."&se=".md5("fp".$user_project['qlty_project_id']."s")."'";
						$actions['green']=6;
						$actions['editable']=1;

						break;
					case $GLOBALS['project_status']['MIDDLE_FILE']:
						// if($current_stage_num=='50')
						// {
							if($time>strtotime($current_stage_stages['50']['begin']) && $time<strtotime($current_stage_stages['50']['end']))
							{
								$actions['text']="请点击此按钮提交中期报告";
								$actions['ac']="javascript:location='/?a=upload&file=4&qltyid=".$user_project['qlty_project_id']."&se=".md5("fp".$user_project['qlty_project_id']."s")."'";
							}else{
								// $actions['text']="提交中期报告截止时间已过";
								$actions['text']="请按进度完成项目研究与实践";
								$actions['ac']="javascript:void(0)";
							}
						// }
		
							$actions['green']=7;
							$actions['editable']=0;
						
						break;
					case $GLOBALS['project_status']['FINAL_FILE']:
						// if($current_stage_num=='50')
						// {
							if($time>strtotime($current_stage_stages['60']['begin']) && $time<strtotime($current_stage_stages['60']['end']))
							{
								$actions['text']="请点击此按钮提交结题材料";
								$actions['ac']="javascript:location='/?a=upload&file=6&qltyid=".$user_project['qlty_project_id']."&se=".md5("fp".$user_project['qlty_project_id']."s")."'";
							}else{
								// $actions['text']="提交中期报告截止时间已过";
								$actions['text']="请按进度完成项目研究与实践";
								$actions['ac']="javascript:void(0)";
							}
						// }
		
							$actions['green']=7;
							$actions['editable']=0;
						
						break;

					case $GLOBALS['project_status']['WAIT_LAST_TRIAL']:
						$actions['text']="结题材料已上传完毕，等待结题评审";
						$actions['ac']="javascript:void(0)";
						$actions['green']=7;
						$actions['editable']=0;
						break;

					case $GLOBALS['project_status']['NEXT_TURN']:
						$actions['text']="等待下一次结题评审，暂缓项目查看评审意见";
						$actions['ac']="javascript:location='/?a=teacher_result&pid=".$user_project['qlty_project_id']."&tid=".$tid."'";
						$actions['green']=16;
						break;

					case $GLOBALS['project_status']['DONE']:
						$actions['text']="项目已结题";
						$actions['ac']="javascript:void(0);";
						$actions['green']=17;
						break;

					default:
						break;
				}
				
				
			}//status-->
			$actions['edit_url']="/?a=edit_project&pid=".$user_project['qlty_project_id']."&tid=".$tid;
			$participants_str="";
			if($participants){
				foreach($participants as $r)
					$participants_str .=$r['teacher_name']."&nbsp;";
			}
			$projects[]=$user_project+Array('participants'=>$participants_str)+Array('assets'=>$qlty_asset_status)+$actions;
		}

	}//if $user_projects

		$dept_arr=$_SESSION['department'];
		$department=array();
		foreach ($dept_arr as $dept) {
			$department[$dept['department_id']]=$dept['department_name'];
		}
		$data['department']=$department;



		$data['qlty_current_stage']=$qlty_current_stage;
		//全部类型
		$data['qlty_category']=(unserialize($_SESSION['qlty_course_category']))+(unserialize($_SESSION['qlty_project_category']))+(unserialize($_SESSION['qlty_team_category']));

		$data['qlty_rank']=unserialize($_SESSION['qlty_rank']);
		$data['qlty_specity']=unserialize($_SESSION['qlty_specity']);
		$data['user_projects']=$projects;
		$data['title'] = $data['top_title'] = '个人信息';
		$data['teacher'] = $_SESSION['teacher'];
		$data['css'][]="index.css";
		render($data);
	}

	//提交项目科初审时的确认单
	public function xmkverify()
	{
		$pid=z(t(v('pid')));
		$tid=z(t(v('tid')));

		$data['pid']=encrypt($pid,c('key'));
		$data['tid']=encrypt($tid,c('key'));
		render($data,'ajax');
	}

	public function xmkverify_check()
	{
		$pid=decrypt( z(t(v('pid'))) ,c('key') );
		$tid=decrypt( z(t(v('tid'))) ,c('key') );
		
		$edudata = self::getEdudataInstance();
		$result = $edudata->update_project_status($pid,$tid,$GLOBALS['project_status']['WAITING_FOR_VERIFY']);
		if($result)
			return ajax_echo('提交项目科初审成功！<script>location="/?a=index"</script>');
		else
			return ajax_echo('提交失败！');
	
	}
 
	public function abandverify()
	{
		$pid=z(t(v('pid')));
		$tid=z(t(v('tid')));
		$edudata = self::getEdudataInstance();
		$result = $edudata->update_project_status($pid,$tid,$GLOBALS['project_status']['APPLYFILE']);
		if($result)
			return ajax_echo('取消提交初审成功！<script>location="/?a=index"</script>');
		else
			return ajax_echo('更新失败！');

	}

	//项目参与人设置
	public function participants()
	{
		//可传递两个参数，是否编辑，项目id，提交时要判断是否为当前用户主持的项目
		$project_id=z(t(v('pid')));
		$tid=z(t(v('tid')));
		$current_teacher_id=$_SESSION['teacher']['teacher_id'];

		//是否为当前用户
		if($tid==$current_teacher_id)
		{
			$edudata = self::getEdudataInstance();
			//验证是否是当前用户项目
			$project_detail=$edudata->get_project_detail_by_id($project_id,$tid);

			if($project_detail['qlty_project_id']>0)
			{
				//当前用户所主持项目
				$status=$project_detail['status'];
				if( $status<$GLOBALS['project_status']['WAITING_FOR_VERIFY'] || $status==$GLOBALS['project_status']['REJECTED'] ||$status==$GLOBALS['project_status']['CHANGING'] ||$status==$GLOBALS['project_status']['WAITING_FOR_UPGRADE'])
				{
					//允许修改参与人的status判断
					//获取项目参与者
				
					$participants = $edudata->get_project_participants($project_id);
					$eight_participants=Array();
					//若为空，则为false
					if($participants){
						foreach($participants as $participant)
							$eight_participants[$participant['order']]=$participant;
					}
					
					$data['project_id']=encrypt($project_id,'projectid');
					$data['participants']=$eight_participants;
					render($data,'ajax');				
				}else{
					return ajax_echo('当前项目状态不允许修改参与人信息！');
				}

			}else{
				//
				return ajax_echo("只能修改本人所主持项目信息");
			}



		}else{
			//非当前用户
			return ajax_echo("只能修改本人信息");
		}

	}

	//更新参与人
	public function update_participants()
	{
		//接收数据
		$project_id=decrypt( z(t(v('pid'))),'projectid' );

		$eight_participants=Array();

		for($i=1;$i<9;$i++)
		{
			$name=z(t(v('pname'.$i)));
			$email=z(t(v('pemail'.$i)));

			if(strlen($name)>12) return ajax_echo("姓名长度不合法");
			//不能单个出现
			if( ($name=="" && $email!="") || ($name!="" && $email==""))
				return ajax_echo('注意第'.$i.'参与人的姓名与邮箱要成对填写！');
			if($email!="" && !validEmail($email))
				return ajax_echo('所填写的第'.$i.'参与人的邮箱不合法');

			//不允许中间空一个参与人不填写
			if($i>1 && $eight_participants[$i-1]['name']=="" && $name!="")
				return ajax_echo('请按顺序依次填写，不能中间间隔！');

			$eight_participants[$i]=Array('name'=>$name,'email'=>$email);
			
		}
		$edudata = self::getEdudataInstance();
		$results = $edudata->update_project_participants($project_id,$eight_participants);
		if($results['err_code']=='0')
			return ajax_echo('恭喜！参与人更新成功！！<script>location="/?a=index";</script>');
		else
			return ajax_echo($results['err_code'].":".$results['err_msg']);

	}


	public function logout()
	{
		foreach( $_SESSION as $k => $v )
		{
			$_SESSION[$k]='';
			unset( $_SESSION[$k] );
		}
		
		return info_page( "成功退出……<script>location = '/?a=login';</script>" );
	}
	
	public function login()
	{
		//计划改为验证COOKIE中是否有access_token，但目前只检测session

		if( is_login() )
		{
			return ajax_echo("已登录，转向中…<script>location = '?a=index';</script>");
		}
		
		$data['title'] = $data['top_title'] = '登录';
		$data['js'][]="keysubmit.js";
		render( $data,'','logindex' );
	}

	
	public function login_check()
	{
		//var_dump($_COOKIE['atk']);exit();
		$email = z(t(v('email')));
		$password = z(t(v('password')));

		if( strlen( $email ) < 1 || strlen( $password ) < 1 )
			return ajax_echo( "电子邮件或密码不能为空" );
		
		$edudata = self::getEdudataInstance($email,$password);
		
		$teacher = $edudata->verify();
		// var_dump($teacher);exit();
		if($teacher['err_code']=='0')
		{
			$_SESSION['NOW_Logining_USER_ID']=$teacher['data']['teacher_id'];
			$_SESSION['temp_teacher']=$teacher['data'];
			//是否已激活
			if( $teacher['data']['is_email_verified']=='1' )
			{				
				$url = '';

				//access_token是否有效
				if(IS_NULL($_COOKIE['atk'.$_SESSION['NOW_Logining_USER_ID']]) || !isset($_COOKIE['atk'.$_SESSION['NOW_Logining_USER_ID']]))
				{
					echo "d";
					//refresh_token是否过期
					if(IS_NULL($_COOKIE['rtk'.$_SESSION['NOW_Logining_USER_ID']]) || !isset($_COOKIE['rtk'.$_SESSION['NOW_Logining_USER_ID']]))
					{
						$url = '/?a=authorize';
					}else{
						$url = '/?a=token';
					}

				}else{
					//这个时候才能算登陆成功，记录session
					$_SESSION['teacher']=$teacher['data'];
					$url = '/?a=index';
				}
				
				//更新last_login_time
				$result=$edudata->update_last_login_time($_SESSION['NOW_Logining_USER_ID']);

				return ajax_echo("成功登录，转向中…<script>location = '".$url."';</script>");
			}else{

				return ajax_echo("请激活账户…<script>location = '/?a=vemail';</script>");
			}

		}else{
			switch ($teacher['err_code']) {
				case '10001':
					//access_token不能用，需清除
					return ajax_echo('异常:'.$teacher['err_code'].',正在处理……<script>$("#form_form_login_notice").load("/?a=refresh");</script>');
					break;
				
				default:
					return ajax_echo(  $teacher['err_code']."  ".$teacher['err_msg'] );
					break;
			}
		}

		
		
	}

	public function authorize()
	{	
		$parameters = Array(
			'client_id' => c('client_id'),
			'client_secret' => c('client_secret'),
			'redirect_uri' => urlencode(c('redirect_uri')),
			'response_type' => 'token',
			'state' => 'test_state',
			'tid' => $_SESSION['NOW_Logining_USER_ID']
		);

		$url = c('authorizeURL')."?".http_build_query($parameters);

		return ajax_echo("认证中…<script>location = '".$url."';</script>");
	
	}

	public function token()
	{	
		$parameters = Array(
			'client_id' => c('client_id'),
			'client_secret' => c('client_secret'),
			'refresh_token' => $_COOKIE['rtk'.$_SESSION['NOW_Logining_USER_ID']],
			'redirect_uri' => urlencode(c('redirect_uri')),
			'grant_type' => 'refresh_token',
		);

		$url = c('tokenURL')."?".http_build_query($parameters);

		return ajax_echo("刷新access_token,认证中…<script>location = '".$url."';</script>");
	
	}

	//接收返回的access_token与refresh_token等
	public function oauth()
	{
		if(is_null($_SESSION['NOW_Logining_USER_ID']) || $_SESSION['NOW_Logining_USER_ID']=="")
			die('Bad Action');
		$need_refresh = z(t(v('nrefresh')));
		if($need_refresh=="gszy")
		{
			setCOOKIE('atk'.$_SESSION['NOW_Logining_USER_ID'],'',time()-43000);
			setCOOKIE('rtk'.$_SESSION['NOW_Logining_USER_ID'],'',time()-1209600);
			return ajax_echo("请重新认证……<script>location = '/?a=authorize';</script>");
		}else{
			$access_token = z(t(v('access_token')));
			$refresh_token = z(t(v('refresh_token')));
			$expires_in = z(t(v('expires_in')));
			$token_type = z(t(v('token_type')));
			$scope = z(t(v('scope')));
			$state = z(t(v('state')));

			if($access_token=="" || $refresh_token=="" || $expires_in=="" || $token_type=="")
				die('Bad parameters');
			//scope、token_type、state之类的暂未处理
			
			setCOOKIE('atk'.$_SESSION['NOW_Logining_USER_ID'],$access_token,time()+$expires_in-1200);

			//14day，比odp提前一天
			setCOOKIE('rtk'.$_SESSION['NOW_Logining_USER_ID'],$refresh_token,time()+1209600);

			//登陆成功，写入SESSION
			$_SESSION['teacher']=$_SESSION['temp_teacher'];
			return ajax_echo("<script>location = '/?a=index';</script>");
		}
	}

	public function history_fund_active()
	{

		$data['title']=$data['top_title']="历史报账账户激活";
		render($data,'','reg');
	}

	public function history_name_check()
	{
		$teacher_name=z(t(v('teacher_name')));
		if($teacher_name=="" || is_null($teacher_name))
			return ajax_echo("请输入您的姓名");
		$edudata=self::getEdudataInstance();
		$teachers=$edudata->get_teachers_by_name($teacher_name);
		if($teachers){
			return ajax_echo("<script>location='/?a=history_email_active&name=$teacher_name'</script>");
		}else{
			return ajax_echo("没有查到此用户，请检查输入是否正确！<b><a href='/?a=register'>如需注册，请点击这里</a></b>");
		}
	}

	public function history_email_active()
	{
		$teacher_name=z(t(v('name')));
		if($teacher_name=="" || is_null($teacher_name))
			return ajax_echo("<script>location='/?a=history_fund_active'</script>");
		$edudata=self::getEdudataInstance();
		$teachers=$edudata->get_teachers_by_name($teacher_name);
		if(!$teachers)
			return ajax_echo("<script>location='/?a=history_fund_active'</script>");

		$data['teacher_name']=$teacher_name;
		$data['teachers']=$teachers;
		$data['title']=$data['top_title']="验证邮箱";
		render($data,'','reg');

	}

	public function register()
	{
		$_SESSION['could_use_captcha']=true;
		session_start();
		
		self::init_generaldata();
		$data['departments'] = $_SESSION['department'];
		$data['nations'] = $_SESSION['nation'];
		$data['native_places'] = $_SESSION['native_place'];
		$data['title']=$data['top_title']="新用户注册";

		$data['css'][]="jquery-ui.css";
		$data['js'][]="timepicker/jquery-ui.min.js";
		$data['js'][]="timepicker/jquery-ui-timepicker-addon.js";

		$data['js'][]="timepicker/jquery-ui-sliderAccess.js";
		$data['js'][]="timepicker/jquery-ui-timepicker-zh-CN.js";
		$data['js'][]="self.js";

		render($data,'','reg');
		
	}

	public function doreg()
	{
		//获取数据

		$captcha = z(t(v('captcha')));
		$email = z(t(v('email')));
		$pwd = z(t(v('pwd')));
		$pwd_again = z(t(v('pwd_again')));
		$school = z(t(v('school')));
		$department1 = z(t(v('department1')));
		$department2 = z(t(v('department2')));
		$staff_id = z(t(v('staff_id')));
		$school_id = z(t(v('schoolid')));
		$teacher_name = z(t(v('teacher_name')));
		$sex = z(t(v('sex')));
		$pro_title=z(t(v("pro_title")));
		$birthday = z(t(v('birthday')));
		$mobile_phone = z(t(v('mobile_phone')));
		$office_phone = z(t(v('office_phone')));
		$nation = z(t(v('nation')));
		$native_place = z(t(v('native_place')));
		$start_work_time =z(t(v('start_work_time')));


		//验证数据

		if(strtolower($captcha) !== strtolower( $_SESSION['captcha_code']) ) 
			return ajax_echo("验证码有误");
		if($email=="")
			return ajax_echo("邮箱不能为空");
		//邮箱有效性验证
		if( !validEmail($email) )
			return ajax_echo("邮箱无效！");

		//还需要检查是否已注册！！
		$edudata=self::getEdudataInstance();
		$has_email = $edudata->has_email($email);
		if($has_email) return ajax_echo("此邮箱已被注册，不能重复");

		if($pwd=="")
			return ajax_echo("密码不能为空");
		if(strlen($pwd)<8)
			return ajax_echo("密码长度至少为8位");
		if($pwd!==$pwd_again)
			return ajax_echo("密码不一致");
		if($school=='1')
		{
			$is_inside_school=1;
			$department_id = $department1;
			$school_id='13967';
			/*if($staff_id=="") return ajax_echo("工号不能为空");
			if(!preg_match("/(000[0-9]{4}$|0123456[0-9]{3}$|0123[0-9]{3}$)/i",$staff_id))
				return ajax_echo("工号无效");*/

		}else if($school=='2'){
			$is_inside_school=1;
			$department_id = $department2;
			$school_id='13967';
			$staff_id="";

		}else if($school=='3'){
			$is_inside_school=2;
			//注意这里进行了硬编码，数据中部门最后一个添加“校外或企业”
			$department_id=81;
			$staff_id="";
			$school_id=0;
			//if($school_id=="") return ajax_echo("学校代码不能为空");
			//if(!preg_match("/[0-9]{5}/i",$school_id)) return ajax_echo("学校代码无效");
		}
		if($teacher_name=="") return ajax_echo("姓名不能为空");
		if(strlen($teacher_name)>12) return ajax_echo("姓名长度不合法");
		if($pro_title=="0" || is_null($pro_title)) return ajax_echo("请选择职称");
		if($birthday=="点击选择时间") return ajax_echo("生日不能为空");

		if($start_work_time=="点击选择时间") return ajax_echo("入职时间不能为空");

		if($mobile_phone=="") return ajax_echo("手机号码不能为空");
		if(!preg_match("/^13[0-9]{1}[0-9]{8}$|15[0-9]{1}[0-9]{8}$|18[0-9]{1}[0-9]{8}$/",$mobile_phone))
			return ajax_echo("手机号码无效！");

		$has_mobile_phone = $edudata->has_mobile_phone($mobile_phone);
		if($has_mobile_phone) return ajax_echo("手机号码已被注册，如有疑问，请联系项目科");

		//if($office_phone=="") return ajax_echo("座机号码不能为空");
		if($office_phone!="" && !preg_match("/(0[0-9]{2,3}[\-][2-9][0-9]{6,7}[\-]?[0-9]?)/i",$office_phone))
			return ajax_echo("座机号码无效");



		//加工数据
		$pwd = md5($pwd);
		$is_working=1;//默认
		$register_time=time();
		$mobile_phone = encrypt($mobile_phone,c('key'));
		//生成邮件验证码
		$email_verificaion_code=dohash(generate_rand_str(7),generate_rand_str(8));
		$start_work_time=strtotime($start_work_time);


		//组装数据
		$params = Array(
			'school_id'=>$school_id,
			'department_id'=>$department_id,
			'staff_id'=>$staff_id,
			'teacher_name'=>$teacher_name,
			'teacher_pwd'=>$pwd,
			'teacher_sex'=>$sex,
			'professional_title'=>$pro_title,
			'is_inside_school'=>$is_inside_school,
			'is_working'=>$is_working,
			'nation_id'=>$nation,
			'native_place_id'=>$native_place,
			'start_work_time'=>$start_work_time,
			'birthday'=>$birthday,
			'email'=>$email,
			'office_phone'=>$office_phone,
			'mobile_phone'=>$mobile_phone,
			'email_verificaion_code'=>$email_verificaion_code,
			'register_time'=>$register_time
		);	
		
		$result = $edudata->add_teacher($params);
		if($result['err_code']=='0')
		{
			$subject = "请激活您的账号";
			$url = c('site_domain')."?a=doactive&code=".$email_verificaion_code."&token=".$edudata->refresh_client_access_token();
			$content = "尊敬的".$teacher_name."：<br>请点击以下链接激活您的账号<br><a href='".$url."'>".$url."</a><br>教务处项目管理科";
			$email_status = send_mail($email,$subject,$content);
			$result=json_decode($email_status);
					//var_dump($result);
			if($result->message=='success')
				return ajax_echo("恭喜！注册成功！请验证邮箱……<script>location = '/?a=vemail';</script>");
		}else{

			return ajax_echo("注册失败！API获取数据错误");
		}

	}

	public function showcaptcha()
	{
		if( !$_SESSION['could_use_captcha'] ) die('bad request');

		require_once(AROOT.'lib'.DS.'captcha.class.php');
		$captcha = new Captcha(180,30,5);
		$captcha->showImg();
		session_start();
		$_SESSION["captcha_code"]= $captcha->getCaptcha();//验证码保存到SESSION中
	}

	public function vemail()
	{
		$data['title']=$data['top_title']="验证邮箱";
		render($data,'','reg');
	}
	
	public function active()
	{
		$data['title']=$data['top_title']="激活账户";
		render($data,'','reg');
	}

	public function doactive()
	{
		$code=z(t(v('code')));
		$access_token=z(t(v('token')));
		
		if($code=="" ||$access_token=="") return ajax_echo("code与token不能为空");

		$edudata=self::getEdudataInstance();
		$status=$edudata->verify_email($code,$access_token);
		/*
		导入的用户密码为空，需要检查密码
		若为空，设置密码
		*/
		if($status=='1'){
			$pwd_null_teacher_id=$edudata->get_teacher_pwd_null($code);
			if($pwd_null_teacher_id>0){
				//设置个安全验证session
				$_SESSION['EDITABLE_TE_PWD']=$code;
				return ajax_echo("<script>location='/?a=init_pwd';</script>");
			}
		}

		$data['status']=$status;
		$data['title']=$data['top_title']="激活账户";
		render($data,'','reg');
	}

	public function init_pwd()
	{
		$code=$_SESSION['EDITABLE_TE_PWD'];
		if($code==""|| is_null($code))
			die('Some params missing! ATTACK!');

		//var_dump($code);
		$_SESSION['EDITABLE_TE_PWD']=NULL;

		$data['title']=$data['top_title']="初始化密码";
		$data['code']=$code;
		render($data,'','reg');
	}

	public function doinitpwd()
	{
		$newpwd=z(t(v("newpwd")));
		$pwd_again=z(t(v("pwd_again")));
		$code=z(t(v('code')));
		if($newpwd=="" || $pwd_again=="") return ajax_echo("不能有空");
		if($newpwd!==$pwd_again) return ajax_echo("两次输入的新密码需要相同！");

		if(!preg_match("/^[0-9a-zA-Z]{8,20}$/",$newpwd)) return ajax_echo("新密码只能为字母或数字，长度为8到20位");

		$edudata=self::getEdudataInstance();
		$new_pwd=md5($newpwd);
		$result = $edudata->init_pwd($new_pwd,$code);

		if($result===true){
			return ajax_echo("修改密码成功……<a href='/?a=login'>使用新密码登陆</a><script>$('#init_pwd_btn').attr('disabled','true');</script>");}
		if($result==='invalidpwd'){
			return ajax_echo("旧密码输入错误！");}
		if($result===false){
			return ajax_echo("发生错误，修改密码不成功");}
	}

	public function reactive()
	{
		$email=z(t(v('email')));

		if($email=="") return ajax_echo("输入或选择您的邮箱");
		//邮箱有效性验证
		if( !validEmail($email) )
			return ajax_echo("邮箱无效！");

		//还需要检查是否已注册！！
		$edudata=self::getEdudataInstance();
		$has_email = $edudata->has_email($email);
		if($has_email) {
			if($has_email['is_email_verified']=='0'){
				//更新verify code
				$email_verificaion_code=dohash(generate_rand_str(7),generate_rand_str(8));
				$teacher_id=$has_email['teacher_id'];

				$result=$edudata->update_verify_code($email,$email_verificaion_code,$teacher_id);
				if( $result ){
					//重新发送email
					$subject = "请激活您的账号";
					$url = c('site_domain')."?a=doactive&code=".$email_verificaion_code."&token=".$edudata->refresh_client_access_token();
					$content = "尊敬的".$has_email['teacher_name']."：<br>请点击以下链接激活您的账号<br><a href='".$url."'>".$url."</a><br>教务处项目科";

					$email_status = send_mail($email,$subject,$content);
					$result=json_decode($email_status);
					//var_dump($result);
					if($result->message=='success'){
						return ajax_echo("已重新发送验证邮件，请登录邮箱验证！<script>$('#reactive_btn').attr('disabled','true');</script>");
					}
				}
			}else{
				return ajax_echo("账户已激活，不能重复操作");
			}

		}

	}

	public function resetpwd()
	{
		$data['title']=$data['top_title']="重置密码";
		render($data,'','reg');
	}

	public function resetpwd_mail()
	{
		$email=z(t(v('email')));

		if($email=="") return ajax_echo("请输入您的邮箱");
		//邮箱有效性验证
		if( !validEmail($email) )
			return ajax_echo("请输入您注册时所用邮箱！！");

		//还需要检查是否已注册！！
		$edudata=self::getEdudataInstance();
		$has_email = $edudata->has_email($email);
		if($has_email) {
			if($has_email['is_email_verified']=='0'){
				return ajax_echo("账户未激活，不能进行重置密码操作！！");

			}else{
				//已激活的账户，才允许进行密码重置操作
				//$se=encrypt($email."m",c('key'));
				$se=md5($email."m");
				$subject = "点击重置您的密码";
				$url = c('site_domain')."?a=doresetpwd&se=".$se."&m=".$email."&t=".$has_email['teacher_id']."&token=".$edudata->refresh_client_access_token();
				$content = "尊敬的".$has_email['teacher_name']."：<br>请点击以下链接重置您的密码<br><a href='".$url."'>".$url."</a><br>教务处项目管理科";

				$email_status = send_mail($email,$subject,$content);
				//var_dump($email_status);
				$result=json_decode($email_status);
				if($result->message=='success'){
					return ajax_echo("已向您的注册邮箱发送密码重置邮件，请登录邮箱查收后操作！<script>$('#resetpwd_mail_btn').attr('disabled','true');</script>");
				}
			}

		}else{
			return ajax_echo("邮箱不存在，请重新输入！找回邮箱请点击<a href='/?a=history_fund_active'>这里</a>");
		}
	}

	public function doresetpwd()
	{
		$m=z(t(v('m')));
		$tid=z(t(v('t')));
		$se=z(t(v('se')));
		$access_token=z(t(v('token')));
		
		if($m=="" ||$access_token=="") return ajax_echo("空值！非法操作");

		if( !validEmail($m) ) return ajax_echo("邮箱非法！");
		if( md5($m."m")!==$se)
			return ajax_echo("非法URL！！");

		$edudata=self::getEdudataInstance();
		$has_email = $edudata->has_email($m);
		if($has_email) {
			if($has_email['is_email_verified']=='0'){
				return ajax_echo("账户未激活，不能进行重置密码操作！！");
			}else{
				
				$data['tid']=$has_email['teacher_id'];
				$data['se']=$se;
				$data['mail']=$m;
				$data['token']=$access_token;
				$data['title']=$data['top_title']="请输入新密码";
				render($data,'','reg');
			}
		}else{
			return ajax_echo("不存在此用户！");
		}

		

	}

	public function newpwd()
	{
		$mail=z(t(v('mail')));
		$tid=z(t(v('tid')));
		$se=z(t(v('se')));
		$access_token=z(t(v('token')));
		$newpwd=z(t(v("newpwd")));
		$pwd_again=z(t(v("pwd_again")));

		if( !validEmail($mail) ) return ajax_echo("邮箱非法！");
		if( md5($mail."m") !==$se)
			return ajax_echo("存在非法操作");

		if($newpwd=="" || $pwd_again=="") return ajax_echo("不能有空");
		if($newpwd!==$pwd_again) return ajax_echo("两次输入的新密码需要相同！");

		if(!preg_match("/^[0-9a-zA-Z]{8,20}$/",$newpwd)) return ajax_echo("新密码只能为字母或数字，长度为8到20位");

		$edudata=self::getEdudataInstance();
		$teacher_id=$edudata->email_set_pwd($newpwd,$tid,$access_token);

		if($teacher_id==$tid && $teacher_id>0)
			return ajax_echo("密码修改成功！请点击<a href='/'>重新登录</a>");



	}


	public function updatepwd()
	{
	
		$data['title']=$data['top_title']="修改密码";
		render($data);
		
	}

	public function doupdatepwd()
	{
		$oldpwd=z(t(v("oldpwd")));
		$newpwd=z(t(v("newpwd")));
		$pwd_again=z(t(v("pwd_again")));
		
		if($oldpwd=="" || $newpwd=="" || $pwd_again=="") return ajax_echo("不能有空");
		if($newpwd!==$pwd_again) return ajax_echo("两次输入的新密码需要相同！");

		if(!preg_match("/^[0-9a-zA-Z]{8,20}$/",$newpwd)) return ajax_echo("新密码只能为字母或数字，长度为8到20位");

		$edudata=self::getEdudataInstance();
		$result = $edudata->update_pwd($newpwd,$oldpwd,$_SESSION['teacher']['teacher_id']);

		if($result===true){
			return ajax_echo("修改密码成功……<script>location = '/?a=logout';</script>");}
		if($result==='invalidpwd'){
			return ajax_echo("旧密码输入错误！");}
		if($result===false){
			return ajax_echo("发生错误，修改密码不成功");}
	}

	public function sysparams()
	{
		$edudata=self::getEdudataInstance();
		$qlty_options=$edudata->get_qlty_option();
		$data['qlty_options']=$qlty_options;

		$data['title']=$data['top_title']="质量工程参数";
		render($data);

	}

	public function init_sysparams()
	{
		//在schoolcloud.sinaapp.com/初始化了，这里只作为备份
		//qlty_option中init
		return ajax_echo("初始化请慎重！注意数据关联。请注释本行后重新执行");
//$this->check_access_token();
//return $this->send_result( "guan li yuan lai cao zuo ");
$qlty_project_category=Array('11'=>"重大教育教学改革项目",'12'=>"重点教育教学改革项目",'13'=>"一般教育教学改革项目");
		$qlty_course_category=Array('21'=>"精品资源共享课",'22'=>"视频公开课",'23'=>"精品建设课程",'24'=>"精品课程",'25'=>"教改课程");
		$qlty_team_category=Array('31'=>"优秀教学团队",'32'=>"一般教学团队");
		$qlty_rank=Array("院校级","中央电大级","市级","国家级");
		$qlty_specity=Array("林业技术类","公路运输类","自动化类","轻纺食品大类","经济贸易类","医药卫生大类","临床医学类","艺术设计类","农林牧渔大类","农业技术类","畜牧兽医类","水产养殖类","农林管理类","交通运输大类","铁道运输类","城市轨道运输类","水上运输类","民航运输类","港口运输类","管道运输类","生化与药品大类","资源开发与测绘大类","材料与能源大类","材料类","能源类","电力技术类","土建大类","建筑设计类","城镇规划与管理类","土建施工类","建筑设备类","工程管理类","市政工程类","房地产类","水利大类","水文与水资源类","水利工程与管理类","水利水电设备类","水土保持与水环境类","制造大类","机械设计制造类","机电设备类","汽车类","电子信息大类","计算机类","电子信息类","通信类","环保、气象与安全大类","环保类","气象类","安全类","轻化工类","纺织服装类","食品类","包装印刷类","财经大类","财政金融类","财务会计类","市场营销类","工商管理类","护理类","药学类","医学技术类","卫生管理类","旅游大类","旅游管理类","餐饮管理与服务类","公共事业大类","公共事业类","公共管理类","公共服务类","文化教育大类","语言文化类","教育类","体育类","教育管理类","艺术设计传媒大类","表演艺术类","广播影视类","公安大类","公安管理类","公安指挥类","公安技术类","部队基础工作类","法律大类","法律实务类","法律执行类","司法技术类","康复训练");
		$qlty_asset_type=Array("11"=>"申报书WORD","12"=>"申报书SWF","13"=>"市级申报书WORD","14"=>"市级申报书SWF","21"=>"任务书WORD","22"=>"任务书SWF","31"=>"开题报告WORD","32"=>"开题报告SWF","41"=>"中期检查报告WORD","42"=>"中期检查SWF","51"=>"项目变更报告WORD","52"=>"项目变更报告SWF","61"=>"结题报告WORD","62"=>"结题报告SWF");
		
		$qlty_current_stage=Array(
			'xm'=>Array(
				'current_stage'=>'0',
				'stages'=>Array(
					'10'=>Array('name'=>'项目申报阶段','begin'=>0,'end'=>0),
					'20'=>Array('name'=>'项目科初审阶段','begin'=>0,'end'=>0),
					'30'=>Array('name'=>'立项评审阶段','begin'=>0,'end'=>0),
					'40'=>Array('name'=>'变更与调整受理阶段','begin'=>0,'end'=>0),
					'50'=>Array('name'=>'项目中期检查阶段','begin'=>0,'end'=>0),
					'60'=>Array('name'=>'结题申请阶段','begin'=>0,'end'=>0),		
					'70'=>Array('name'=>'结题评审阶段','begin'=>0,'end'=>0)
					)
				),
			'kc'=>Array(
				'current_stage'=>'0',
				'stages'=>Array(
					'10'=>Array('name'=>'项目申报阶段','begin'=>0,'end'=>0),
					'20'=>Array('name'=>'项目科初审阶段','begin'=>0,'end'=>0),
					'30'=>Array('name'=>'立项评审阶段','begin'=>0,'end'=>0),
					'40'=>Array('name'=>'变更与调整受理阶段','begin'=>0,'end'=>0),
					'50'=>Array('name'=>'项目中期检查阶段','begin'=>0,'end'=>0),
					'60'=>Array('name'=>'结题申请阶段','begin'=>0,'end'=>0),		
					'70'=>Array('name'=>'结题评审阶段','begin'=>0,'end'=>0)
					)
				),
			'tm'=>Array(
				'current_stage'=>'0',
				'stages'=>Array(
					'10'=>Array('name'=>'项目申报阶段','begin'=>0,'end'=>0),
					'20'=>Array('name'=>'项目科初审阶段','begin'=>0,'end'=>0),
					'30'=>Array('name'=>'立项评审阶段','begin'=>0,'end'=>0),
					'40'=>Array('name'=>'变更与调整受理阶段','begin'=>0,'end'=>0),
					'50'=>Array('name'=>'项目中期检查阶段','begin'=>0,'end'=>0),
					'60'=>Array('name'=>'结题申请阶段','begin'=>0,'end'=>0),		
					'70'=>Array('name'=>'结题评审阶段','begin'=>0,'end'=>0)
					)
				),
		);

		$qlty_project_category_str=serialize($qlty_project_category);
		$qlty_course_category_str=serialize($qlty_course_category);
		$qlty_team_category_str=serialize($qlty_team_category);
		$qlty_rank_str=serialize($qlty_rank);
		$qlty_specity_str=serialize($qlty_specity);
		$qlty_asset_type_str=serialize($qlty_asset_type);
		$qlty_current_stage_str=serialize($qlty_current_stage);

		$sql="INSERT INTO `qlty_option`(`qlty_option_name`,`qlty_option_value`) VALUES ('qlty_project_category','".$qlty_project_category_str."'),('qlty_course_category','".$qlty_course_category_str."'),('qlty_team_category','".$qlty_team_category_str."'),('qlty_rank','".$qlty_rank_str."'),('qlty_specity','".$qlty_specity_str."'),('qlty_asset_type','".$qlty_asset_type_str."'),('qlty_current_stage','".$qlty_current_stage_str."')";
		run_sql($sql);
	}


	//申报教改课程
	public function capply()
	{
		// 申报课程
		// 默认只能申报校级
		// 只能在建一门
		return info_page("课程项目申报尚未开始！<a href='/?a=index'>点击返回</a>");
		$tid=$_SESSION['teacher']['teacher_id'];
		$edudata = self::getEdudataInstance();
		$user_projects = $edudata->get_user_projects($tid);
		if($user_projects){
			foreach($user_projects as $project)
			{
				//如果有未结题（在研）的课程改革项目，则不能申请
				if($project['type']=='kc' && $project['status']!=$GLOBALS['project_status']['DONE'] && $project_status['rank']==0)
					return info_page("您有在研的课程改革项目，暂时不能再申报！<a href='/?a=index'>点击返回</a>");

			}
		}

		$data['qlty_course_category']=unserialize($_SESSION['qlty_course_category']);

		$data['qlty_rank']=unserialize($_SESSION['qlty_rank']);
		$data['qlty_specity']=unserialize($_SESSION['qlty_specity']);

		$data['title']=$data['top_title']="教改课程申报";
		render($data);
	}

	public function papply()
	{
		$qlty_current_stage=unserialize(ss('qlty_current_stage'));
		//var_dump($qlty_current_stage);
		if (strtotime($qlty_current_stage['xm']['stages']['10']['end'])<time()) {
			return info_page("本轮教改项目申报已结束！<a href='/?a=index'>点击返回</a>");
		}

		// 申报教改项目
		//默认只能申报校级
		//只能在建一门
		$tid=$_SESSION['teacher']['teacher_id'];
		$edudata = self::getEdudataInstance();
		$user_projects = $edudata->get_user_projects($tid);
		//是否有在研校级教改项目
		$rank_school=FALSE;
		//是否有在研市级教改项目
		$rank_capital=FALSE;
		//今年是否申报
		$apply_once=FALSE;
		//var_dump($user_projects);
		if($user_projects){
			foreach($user_projects as $project)
			{
				//已经在本年度申报了一次，委托项目除外
				if($project['type']=='xm' && $project['status']!=$GLOBALS['project_status']['DONE'] && $project['status']!=$GLOBALS['project_status']['ABANDON'] && date('Y',$project['created_time'])==date('Y',time()) && $project['category']!='14'){
					$apply_once=TRUE;
				};

				//如果有未结题（在研）的校级改革项目(除放弃的)，则不能申请校级项目
				if($project['type']=='xm' && $project['status']!=$GLOBALS['project_status']['DONE'] && $project['status']!=$GLOBALS['project_status']['ABANDON'] && $project['status']!=$GLOBALS['project_status']['REJECTED'] && $project['rank']==0 && $project['category']!='14'){
					$rank_school=TRUE;
				};

				if($project['type']=='xm' && $project['status']!=$GLOBALS['project_status']['DONE'] && $project['status']!=$GLOBALS['project_status']['ABANDON'] && $project['rank']>0 && $project['category']!='14'){
					$rank_capital=TRUE;
				}

			}

			if($rank_school && $rank_capital)
				return info_page("您同时在研的校级与市级教育教学改革项目，不能再申报！<a href='/?a=index'>点击返回</a>");
			//此次已申报了一项（校级或市级）
			if($apply_once)
				return info_page("在本次申报中您已申报一项教改项目，不能再申报！<a href='/?a=index'>点击返回</a>");
		}

		$data['rank_school']=$rank_school;
		$data['rank_capital']=$rank_capital;

		$data['qlty_project_category']=unserialize($_SESSION['qlty_project_category']);

		$data['qlty_rank']=unserialize($_SESSION['qlty_rank']);
		$data['qlty_specity']=unserialize($_SESSION['qlty_specity']);

		$data['title']=$data['top_title']="教改课程申报";
		render($data);
	}


	public function add_project()
	{
		//接收数据
		$project_type=z(t(v("project_type")));
		$category=z(t(v("category")));
		$course_name=z(t(v("course_name")));
		$belong_cqdd=z(t(v("belong_cqdd")));
		$rank=z(t(v("rank")));
		$specialty=z(t(v("specialty")));
		$course_url=v("course_url");
		$is_backbone=z(t(v("is_backbone")));
		$sessions=z(t(v("sessions")));
		$funds=z(t(v("funds")));
		$research_year=z(t(v("research_year")));
		//$research_year=2;
		$achievement=z(t(v("achievement")));
		$course_experience=z(t(v("course_experience")));
		$teacher_id=$_SESSION['teacher']['teacher_id'];

		//匹配出来数据
		//待后续实现,hxd 13/02/22



		//组装数据
		$params=Array(
			'director_id'=>$teacher_id,
			'name'=>$course_name,
			'type'=>$project_type,
			'category'=>$category,
			'rank'=>$rank,
			'belong_cqdd'=>$belong_cqdd,
			'belong_specialty'=>$specialty,
			'course_url'=>$course_url,
			'is_backbone'=>$is_backbone,
			'sessions'=>$sessions,
			'apply_funds'=>$funds,
			'research_year_num'=>$research_year,
			'achievement'=>$achievement,
			'created_time'=>time()
		);
		if($course_experiment!=="")
		{
			$params =$params+Array('course_teach_experience'=>$course_experience);
		}
		//var_dump($params);
		$edudata = self::getEdudataInstance();
		$qlty_project_id = $edudata->add_qlty_project($params);

		if($qlty_project_id) 
		{
			//防止恶意修改URL上传文件,验证后即销毁此session
			$_SESSION['sys_need_upload_file']=TRUE;

			//qlty_project_id  project_type  file(文档类型asset_type，头数字)
			//return ajax_echo("操作成功，下一步请提交材料<script>location = '/?a=upload&qltyid=".$qlty_project_id."&ptype=".$project_type."&file=1&se=".encrypt("f1p".$qlty_project_id."s",c("key"))."';</script>");
			return ajax_echo("操作成功！稍后请完成添加参与人与项目材料！……<script>location='/?a=index'</script>");
		}else{
			return ajax_echo("添加失败！请检查数据是否完整");
		}

	}

	public function upload()
	{
		//if($_SESSION['sys_need_upload_file']){
			//unset($_SESSION['sys_need_upload_file']);
			$pid=z(t(v("qltyid")));
			$tid=$_SESSION['teacher']['teacher_id'];
			$asset_type_head=z(t(v("file")));
			//安全验证字符串,防止而已修改url串
			$se=z(t(v('se')));

			if(md5("fp".$pid."s") !=$se)
				die("Bad Request");

			/*
			*验证pid与tid一致
			*然后查询pid所有asset
			*/
			$edudata = self::getEdudataInstance();
			$qlty_asset_status = $edudata->get_qlty_asset_status($pid,$tid);

			$project=$edudata->get_project_detail_by_id($pid,$tid);
			//var_dump($project);
			$f=1;
			$status_arr=array();
			//如果项目状态为申报，且为市级,提交市级材料
			if($project['rank']>0 && ($project['status']<$GLOBALS['project_status']['WAITING_FOR_VERIFY'] || $project['status']==$GLOBALS['project_status']['WAITING_FOR_UPGRADE'])) $f=3;
			//$status_arr=Array(1=>"N",2=>"N",3=>"N",4=>"N");
			
			//如果是准备结题的项目（暂时没有区分是课程项目还是教改项目），要上传结题材料
			if($project['status']==$GLOBALS['project_status']['FINAL_FILE']){
				$file_num=9;
			}else{
				$file_num=1;
			}
			//SWF不上传，跳过，自增2
			for($i=$f;$i<$f+$file_num;$i=$i+2)
			{
				$status_arr +=array($i=>"N");
			}

			if($qlty_asset_status!==FALSE)
			{
				//目前只要2就够了，以后也许某个阶段需要多种类型的材料上传
				//
				/*
				* 015-03-25
				* FlashPaper转换有诸多问题，现在取消，我手动转
				* 所以这里只需要第一个word即可
				* 注意：upload.tpl中也有修改 file_num 此值
				*/
				
				for($i=$f;$i<$f+$file_num;$i++)
				{
					//$status_arr[$i]="N";
					foreach($qlty_asset_status as $qs)
					{

						if($qs['asset_type']==($asset_type_head.$i) && $qs['asset_uri']!="")
						{
							$status_arr[$i]="Y";
							break;
						}
					}

				}
			}

			//如果目前状态为FINAL_FILE，而所有文档已上传，则更改为WAIT_LAST_TRIAL
			if(!array_search("N",$status_arr) && $project['status'] == $GLOBALS['project_status']['FINAL_FILE'])
			{
				$result=$edudata->update_project_status($project['qlty_project_id'],$tid,$GLOBALS['project_status']['WAIT_LAST_TRIAL']);
			}
			// var_dump($status_arr);
			// var_dump($qlty_asset_status);

			$data['project']=$project;
			$data['status_arr']=$status_arr;
			$data['qlty_project_id']=$pid;
			$data['asset_type_head']=$asset_type_head;
			$data['qlty_asset_type']=unserialize($_SESSION['qlty_asset_type']);
			$data['file_start'] = $f;
			$data['file_end']= $file_num;
			$data['title']=$data['top_title']="上传资料";

			$data['title']=$data['top_title']="上传资料";
			render($data);

		//}else{die("Bad Request");}
	}
	
	public function uploadform()
	{
		$qlty_project_id=z(t(v('qid')));
		$asset_type=z(t(v("atp")));
		$tid=$_SESSION['teacher']['teacher_id'];

		//作为文件目录，区分证明材料certification目录
		$category="qlty";
		//生成安全验证字符串
		$str='pidis'.$qlty_project_id;

		//再次验证
		$edudata = self::getEdudataInstance();

		$project_detail=$edudata->get_project_detail_by_id($qlty_project_id,$tid);
		$status_editable=false;
		$status=$project_detail['status'];
		//var_dump($project_detail);
		if($status<$GLOBALS['project_status']['WAITING_FOR_VERIFY'] || $status==$GLOBALS['project_status']['REJECTED'] || $status==$GLOBALS['project_status']['WAITING_FOR_UPGRADE'] || $status==$GLOBALS['project_status']['FINAL_FILE'])
		{
			$status_editable=true;
		}
		//var_dump($status_editable);

		$qlty_asset_status = $edudata->get_qlty_asset_status($qlty_project_id,$tid);
		$disabled_btn=false;
		$asset_uri="";
		if($qlty_asset_status!==FALSE)
		{

			foreach($qlty_asset_status as $qs){
				if($qs['asset_type']==$asset_type && $qs['asset_uri']!="")
				{
					$asset_uri=$qs['asset_uri'];
					$asset_id=$qs['asset_id'];
					$disabled_btn=true;
					break;
				}
			}
		}
		
		$data['status_editable']=$status_editable;
		$data['disabled_btn']=$disabled_btn;
		$data['asset_id']=$asset_id;
		$data['asset_uri']=$asset_uri;
		$data['pid']=$qlty_project_id;
		$data['asset_type']=$asset_type;
		$data['category']=$category;
		//用格林威治时间保证一致
		$data['encrypt_str']=md5($str.gmdate("Ymd",time()));
		
		$filetype=substr($asset_type,1);
		$data['filetype']="*.doc";
		// if($filetype=='1'){
		// 	$data['filetype']="*.doc";
		// }else if($filetype=='2'){
		// 	$data['filetype']="*.SWF";
		// }
/*		else if($filetype=='3'){
			$data['filetype']="*.pdf";
		}else if($filetype=='4'){
			$data['filetype']="*.ppt";
		}*/
		//结题材料中的其他支撑材料
		if(($filetype%2)===0){
			$data['filetype']="*.SWF";
		}
		if($filetype=='9'){
			$data['filetype']="*.rar";
		}

		if($asset_type=='13'){
			$data['filetype']="*.doc";
		}
		else if($asset_type=="14"){
			$data['filetype']="*.swf";
		}

		$data['js'][]="swfupload/swfupload.js";//这个改用SAE lib
		$data['js'][]="swfupload/fileprogress.js";
		$data['js'][]="swfupload/handlers.js";
		$data['js'][]="swfupload/swfupload.queue.js";

		$data['css'][]="swfupload.css";
		$data['title']=$data['top_title']="上传";
		render($data,'ajax','uploadform');
	}

	function ajax_update_asset()
	{
	//if($_SESSION['sys_need_upload_file']){
		//unset($_SESSION['sys_need_upload_file']);

		/*
		*这里需要验证，确认当前用户正在操作其主持的 状态为目前状态的项目
		*以后再补
		*/
		$fileName=z(t(v("fileName")));
		$type=z(t(v("type")));
		$pid=z(t(v("pid")));
		$qlty_asset_type=unserialize($_SESSION['qlty_asset_type']);
		$params=Array(
			'asset_name'=>$qlty_asset_type[$type],
			'qlty_project_id'=>$pid,
			'asset_uri'=>$fileName,
			'asset_type'=>$type
		);
		$edudata = self::getEdudataInstance();
		$asset_id = $edudata->add_qlty_project_asset($params);
		if($asset_id>0)
		{
			return ajax_echo("上传成功，数据已记录！");
		}else{
			return ajax_echo("发生错误，数据未成功记录！请联系管理员处理！");
		}


	//}else{die("Bad Request");}

	}

	public function delete_asset()
	{
		//删除数据库中数据
		$project_id=z(t(v('pid')));
		$asset_uri=z(t(v('asset_uri')));
		$asset_id=z(t(v('asset_id')));
		$tid=$_SESSION['teacher']['teacher_id'];
		$edudata = self::getEdudataInstance();

		$project_detail=$edudata->get_project_detail_by_id($project_id,$tid);
		if($project_detail){
			$status=$project_detail['status'];
			if($status<$GLOBALS['project_status']['WAITING_FOR_VERIFY'] || $status==$GLOBALS['project_status']['REJECTED'] || $status==$GLOBALS['project_status']['WAITING_FOR_UPGRADE'] || $status==$GLOBALS['project_status']['FINAL_FILE'])
			{
				$result=$edudata->delete_asset_by_id($asset_id);
				if($result)
					return ajax_echo('删除成功');
			}
		}



	}

	public function mycourse()
	{
	
		$data['title']=$data['top_title']="课程项目状态";
		render($data);
	}

	public function stage()
	{
		if(!is_admin()){
			die("Bad Request");
		}
		//var_dump($_SESSION['qlty_current_stage']);
		self::init_generaldata();
		$data['qlty_current_stage']=unserialize($_SESSION['qlty_current_stage']);
		$data['title']=$data['top_title']="全部状态设置";
		render($data);
	}

	public function qltystage()
	{
		if(!is_admin()){
			die("Bad Request");
		}
		$type=z(t(v('type')));
		if($type=='' ||is_null($type)) die('Lost parameters!');
		$qlty_current_stage=unserialize(ss('qlty_current_stage'));
		$data['qlty_current_stage']=$qlty_current_stage[$type];

		$data['css'][]="jquery-ui.css";
		$data['css'][]="jquery-ui-timepicker-addon.css";
		$data['js'][]="timepicker/jquery-ui.min.js";
		$data['js'][]="timepicker/jquery-ui-timepicker-addon.js";
		$data['js'][]="timepicker/jquery-ui-sliderAccess.js";
		$data['js'][]="timepicker/jquery-ui-timepicker-zh-CN.js";
		$data['js'][]="self.js";
		$data['title']=$data['top_title']="设置质量工程系统阶段";
		$data['type']=$type;
		render($data);
	}

	public function update_stage()
	{
		$qlty_type=z(t(v('qlty_type')));
		$new_stage=Array(
			'current_stage'=>z(t(v('current_stage'))),
			'stages'=>Array(
				'10'=>Array('name'=>'项目申报阶段','begin'=>z(t(v('stage_begin10'))),'end'=>z(t(v('stage_end10'))) ),
				'20'=>Array('name'=>'项目科初审阶段','begin'=>z(t(v('stage_begin20'))),'end'=>z(t(v('stage_end20'))) ),
				'30'=>Array('name'=>'立项评审阶段','begin'=>z(t(v('stage_begin30'))),'end'=>z(t(v('stage_end30'))) ),
				'40'=>Array('name'=>'变更与调整受理阶段','begin'=>z(t(v('stage_begin40'))),'end'=>z(t(v('stage_end40'))) ),
				'50'=>Array('name'=>'项目中期检查阶段','begin'=>z(t(v('stage_begin50'))),'end'=>z(t(v('stage_end50'))) ),
				'60'=>Array('name'=>'结题申请阶段','begin'=>z(t(v('stage_begin60'))),'end'=>z(t(v('stage_end60'))) ),		
				'70'=>Array('name'=>'结题评审阶段','begin'=>z(t(v('stage_begin70'))),'end'=>z(t(v('stage_end70'))) )
				)
			);
		//print_r($qlty_current_stage);exit();
		$edudata = self::getEdudataInstance();
		$old_stage=unserialize(ss('qlty_current_stage'));
		$old_stage[$qlty_type]=$new_stage;
		$qlty_current_stage=$old_stage;

		$qlty_option_id = $edudata->update_qlty_option('qlty_current_stage',serialize($qlty_current_stage));
		if($qlty_option_id>0)
		{
			$_SESSION['qlty_current_stage']=serialize($qlty_current_stage);
			return ajax_echo('修改成功');
		}

	}

	public function xmktrial()
	{
		if(!is_xmk_trialor()){
			die("Bad Request");
		}

		$edudata = self::getEdudataInstance();
		$status=$GLOBALS['project_status']['WAITING_FOR_VERIFY'];
		$projects=$edudata->get_wait_for_trial_projects($status);

		$waiting_projects=$edudata->get_less_than_the_status_projects($GLOBALS['project_status']['FIRST_TRIAL']);
		$wprojects=array();
		foreach($waiting_projects as $wp)
		{
			$participants = $edudata->get_project_participants($wp['qlty_project_id']);
			$participants_str="";
			if($participants){
				foreach($participants as $r)
					$participants_str .=$r['teacher_name']."&nbsp;";
			}
			$wprojects[]=$wp+Array('participants'=>$participants_str);
		}

		$dept_arr=$_SESSION['department'];
		$department=array();
		foreach ($dept_arr as $dept) {
			$department[$dept['department_id']]=$dept['department_name'];
		}
		$data['department']=$department;
		$data['projects']=$projects;
		$data['status_arr']=array_flip($GLOBALS['project_status']);
		$data['waiting_projects']=$wprojects;
		$data['qlty_specity']=unserialize($_SESSION['qlty_specity']);
		$data['title']=$data['top_title']="项目科初审";
		$data['js'][]="jquery.dataTables.min.js";
		$data['js'][]="pdata.js";
		$data['css'][]="jquery.dataTables.css";
		render($data);
	}

	public function first_trial()
	{
		if(!is_xmk_trialor()){
			die("Bad Request");
		}

		$edudata = self::getEdudataInstance();
		$status=$GLOBALS['project_status']['FIRST_TRIAL'];
		$w_projects=$edudata->get_wait_for_trial_projects($status);

		$wprojects=array();
		if(is_array($w_projects)&& !empty($w_projects))
		{
			foreach($w_projects as $wp)
			{
				$participants = $edudata->get_project_participants($wp['qlty_project_id']);
				$participants_str="";
				if($participants){
					foreach($participants as $r)
						$participants_str .=$r['teacher_name']."&nbsp;";
				}
				$wprojects[]=$wp+Array('participants'=>$participants_str);
			}
		}
		$dept_arr=$_SESSION['department'];
		$department=array();
		foreach ($dept_arr as $dept) {
			$department[$dept['department_id']]=$dept['department_name'];
		}
		$data['department']=$department;
		$data['projects']=$projects;
		$data['status_arr']=array_flip($GLOBALS['project_status']);
		$data['waiting_projects']=$wprojects;
		$data['qlty_specity']=unserialize($_SESSION['qlty_specity']);
		$data['title']=$data['top_title']="项目科初审";
		$data['js'][]="jquery.dataTables.min.js";
		$data['js'][]="pdata.js";
		$data['css'][]="jquery.dataTables.css";
		render($data);
	}

	public function xmktrial_detail()
	{
		if(!is_xmk_trialor()){
			die("Bad Request");
		}
		$teacher_id=z(t(v('tid')));
		$qlty_project_id=z(t(v('pid')));

		$edudata = self::getEdudataInstance();
		//获取项目信息
		$project_detail=$edudata->get_project_detail_by_id($qlty_project_id,$teacher_id);
		//项目主持人信息
		$director_detail=$edudata->get_director_detail($teacher_id);

		//获取参与人信息
		$participants = $edudata->get_project_participants($qlty_project_id);
		// var_dump($participants);exit();
		//包含参与项目信息的数组
		$participants_detail = Array();
		if($participants)
		{
			foreach ($participants as $p) {
				//获取参与的项目
				$participant_projects = $edudata->get_unfinished_participant_projects($p['teacher_id']);
				if($participant_projects)
				{
					$participants_detail[$p['teacher_id']] = $p + array('participant_projects'=>$participant_projects);
				}else{
					$participants_detail[$p['teacher_id']] = $p;
				}
			}
		}

		// var_dump($participants_detail);exit();
		//申报书doc与PDF(其他材料这个时候还未上传)
		$assets=$edudata->get_project_assets($qlty_project_id);

		$data['qlty_category']=(unserialize($_SESSION['qlty_course_category']))+(unserialize($_SESSION['qlty_project_category']))+(unserialize($_SESSION['qlty_team_category']));

		$data['qlty_rank']=unserialize($_SESSION['qlty_rank']);
		$data['qlty_specity']=unserialize($_SESSION['qlty_specity']);
		$data['project_detail']=$project_detail;
		$data['director_detail']=$director_detail;
		$data['participants']=$participants;
		$data['participants_detail'] = $participants_detail;
		$data['assets']=$assets;
		$data['title']=$data['top_title']="项目科初审";
		render($data);
	}

	public function xmktrial_pass()
	{

		if(!is_xmk_trialor()){
			die("Bad Request");
		}
		$email=z(t(v('email')));
		$teacher_name=z(t(v('tname')));
		$mobile_phone=z(t(v('phone')));
		$project_name=urldecode(z(t(v('project_name'))));
		$teacher_id=z(t(v('tid')));
		$project_id=z(t(v('pid')));

		$data['email']=$email;
		$data['teacher_name']=$teacher_name;
		$data['mobile_phone']=$mobile_phone;
		$data['project_name']=$project_name;
		$data['teacher_id']=$teacher_id;
		$data['project_id']=$project_id;
		render($data,'ajax');

	}

	public function xmktrial_refuse()
	{
		if(!is_xmk_trialor()){
			die("Bad Request");
		}
		$email=z(t(v('email')));
		$teacher_name=z(t(v('tname')));
		$mobile_phone=z(t(v('phone')));
		$project_name=urldecode(z(t(v('project_name'))));
		$teacher_id=z(t(v('tid')));
		$project_id=z(t(v('pid')));

		$data['email']=$email;
		$data['teacher_name']=$teacher_name;
		$data['mobile_phone']=$mobile_phone;
		$data['project_name']=$project_name;
		$data['teacher_id']=$teacher_id;
		$data['project_id']=$project_id;
		render($data,'ajax');
	}

	public function pass_message()
	{
		$email=z(t(v('email')));
		$teacher_name=z(t(v('teacher_name')));
		$mobile_phone=z(t(v('mobile_phone')));
		$project_name=z(t(v('project_name')));
		$teacher_id=z(t(v('tid')));
		$project_id=z(t(v('pid')));

		$send_sms=z(t(v('send_sms')));

		//更新项目状态
		$edudata = self::getEdudataInstance();
		$result=$edudata->update_project_status($project_id,$teacher_id,$GLOBALS['project_status']['FIRST_TRIAL']);
		if($result[0]['qlty_project_id']>0){
			//email默认发送
			
			//组装Email
			$subject="项目初审通过";
			$content="尊敬的".$teacher_name."：<br><br>"
					."您的《".$project_name."》项目已通过项目管理科初审，即将参加专家评审。请您登陆质量工程信息系统查看（点击此链接<a href='http://zlgc.cqtbi.edu.cn/'>http://zlgc.cqtbi.edu.cn/</a>）。<br><br>"
					."此邮件由系统自动发出，请勿回复。如有疑问，欢迎咨询教务处项目科42861081";
			$result="";
			$send_email_result=send_mail( $email , $subject , $content );
			$result=json_decode($send_email_result);
					//var_dump($result);
			if($result->message=='success')
				$result="邮件发送成功";
			else
				$result="邮件发送失败";

			if($send_sms=="on")
			{
				$content="尊敬的".$teacher_name."您好，您的项目已通过项目科初审，即将参加专家评审。【质量工程网】";
				$send_sms_result=send_sms($mobile_phone,$content);
				if($send_sms_result=='1')
					$result .="短信已发送成功<br>";
				else
					$result .="短信发送失败";
			}

			$r=$edudata->update_project_apply_time($project_id,$teacher_id);
			return ajax_echo($result."<script>$('#pass_message_btn').attr('disabled','true');location='/?a=xmktrial'</script>");
			
		}else{
			
			return ajax_echo("项目状态更新失败");
		}
	}

	public function refuse_message()
	{
		$email=z(t(v('email')));
		$teacher_name=z(t(v('teacher_name')));
		$mobile_phone=z(t(v('mobile_phone')));
		$project_name=z(t(v('project_name')));
		$teacher_id=z(t(v('tid')));
		$project_id=z(t(v('pid')));

		$reason=z(t(v('reason')));
		$send_sms=z(t(v('send_sms')));

		if($reason=="" || strlen($reason)<5)
			return ajax_echo("原因不能为空或少于5字！");
		//更新项目状态
		$edudata = self::getEdudataInstance();
		$result=$edudata->update_project_status($project_id,$teacher_id,$GLOBALS['project_status']['REJECTED']);
		if(!$result)
			return ajax_echo("项目状态更新失败");

		//email默认发送
		
		//组装Email
		$subject="项目没有通过初审";
		$content="尊敬的".$teacher_name."：<br><br>"
				."您的《".$project_name."》项目没有通过初审，原因为：<br>"
				."<b>".$reason."</b><br>"
				."。请您登陆质量工程信息系统查看（点击此链接<a href='http://zlgc.cqtbi.edu.cn/'>http://zlgc.cqtbi.edu.cn/</a>）。<br><br>"
				."此邮件由系统自动发出，请勿回复。如有疑问，欢迎咨询教务处项目科42861081";
		$result="";
		$send_email_result=send_mail( $email , $subject , $content );
		$result=json_decode($send_email_result);
					//var_dump($result);
		if($result->message=='success')
			$result="邮件发送成功";
		else
			$result="邮件发送失败";

		if($send_sms=="on")
		{
			$content="尊敬的".$teacher_name."您好，您的项目没有通过项目科初审，原因为“".$reason."”，请修改后尽快重新提交。【质量工程网】";
			$send_sms_result=send_sms($mobile_phone,$content);
			if($send_sms_result=='1')
				$result .="短信已发送成功<br>";
			else
				$result .="短信发送失败";
		}

		
		return ajax_echo($result."<script>$('#refuse_message_btn').attr('disabled','true');location='/?a=xmktrial'</script>");

	}

	public function edit_project()
	{
		$project_id=z(t(v('pid')));
		$teacher_id=z(t(v('tid')));
		
		$current_teacher_id=$_SESSION['teacher']['teacher_id'];
		//只能修改本人项目信息
		if($teacher_id==$current_teacher_id )
		{
			$edudata = self::getEdudataInstance();
			//获取项目信息
			$project_detail=$edudata->get_project_detail_by_id($project_id,$teacher_id);

			//项目主持人信息
			$director_detail=$edudata->get_director_detail($teacher_id);

			//获取参与人信息
			$participants = $edudata->get_project_participants($project_id);
			
			//申报书doc与PDF(其他材料这个时候若未上传或上传后被删除)
			$assets_arr=$edudata->get_project_assets($project_id);
			//var_dump($assets_arr);
			$qlty_asset_type=unserialize($_SESSION['qlty_asset_type']);
			$assets=array();
			if(empty($assets_arr)){
				$assets=Array(
					'11'=>Array('asset_name'=>$qlty_asset_type['11'],'asset_type'=>'11'),
					'12'=>Array('asset_name'=>$qlty_asset_type['12'],'asset_type'=>'12'),
					'13'=>Array('asset_name'=>$qlty_asset_type['13'],'asset_type'=>'13'),
					'14'=>Array('asset_name'=>$qlty_asset_type['14'],'asset_type'=>'14'),
				);
			}else{
				foreach($assets_arr as $asset){
					$assets[$asset['asset_type']]=Array(
						'asset_name'=>$asset['asset_name'],
						'asset_uri'=>$asset['asset_uri']
						);
				}
			}

			//var_dump($assets);
			$data['qlty_category']=(unserialize($_SESSION['qlty_course_category']))+(unserialize($_SESSION['qlty_project_category']))+(unserialize($_SESSION['qlty_team_category']));
			$data['qlty_specity']=unserialize($_SESSION['qlty_specity']);
			$data['qlty_rank']=unserialize($_SESSION['qlty_rank']);
			$data['qlty_course_category']=unserialize($_SESSION['qlty_course_category']);

			$data['project_detail']=$project_detail;
			$data['director_detail']=$director_detail;
			$data['participants']=$participants;
			$data['assets']=$assets;
			$data['title']=$data['top_title']="修改项目信息";

			$data['qlty_rank']=unserialize($_SESSION['qlty_rank']);
			$data['qlty_specity']=unserialize($_SESSION['qlty_specity']);
			render($data);

		}else{
			return info_page("只能修改用户个人自己的信息");
		}

	}


	public function update_project()
	{
		$project_type=z(t(v("project_type")));
		$category=z(t(v("category")));
		$course_name=z(t(v("course_name")));
		$belong_cqdd=z(t(v("belong_cqdd")));
		$rank=z(t(v("rank")));
		$specialty=z(t(v("specialty")));
		$course_url=z(t(v('course_url')));
		$funds=z(t(v("funds")));
		$research_year=z(t(v("research_year")));
		//$research_year=2;
		$achievement=z(t(v("achievement")));
		$course_experience=z(t(v("course_experience")));
		$teacher_id=$_SESSION['teacher']['teacher_id'];

		$project_id=z(t(v('project_id')));
		$qlty_current_stage=unserialize(ss('qlty_current_stage'));
		//匹配出来数据
		//待后续实现,hxd 13/02/22
		$edudata = self::getEdudataInstance();

		$project_detail=$edudata->get_project_detail_by_id($project_id,$teacher_id);

		if($project_detail){
			$status=$project_detail['status'];
			//项目提交初审前(修改，要部门审核推荐)、初审不通过、中期调整
			if($status==$GLOBALS['project_status']['REJECTED'] && ($qlty_current_stage[$project_type]['current_stage']=='20'))
			{
				$status=$GLOBALS['project_status']['WAITING_FOR_VERIFY'];
			}
			//组装数据
			$params=Array(
				'qlty_project_id'=>$project_id,
				'director_id'=>$teacher_id,
				'name'=>$course_name,
				'type'=>$project_type,
				'category'=>$category,
				'rank'=>$rank,
				'belong_cqdd'=>$belong_cqdd,
				'belong_specialty'=>$specialty,
				'course_url'=>$course_url,
				'apply_funds'=>$funds,
				'research_year_num'=>$research_year,
				'achievement'=>$achievement,
				'status'=>$status
				);
			if($course_experiment!=="")
			{
				$params =$params+Array('course_teach_experience'=>$course_experience);
			}

			$result = $edudata->update_qlty_project($params);
			if($result[0]['qlty_project_id']==$project_id)
				return ajax_echo("项目提交成功……<script>location='/?a=index';</script>");

		}

	}

	public function refresh_and_redirect_index()
	{
		return ajax_echo("跳转主页面中……<script>location='/?a=index';</script>");
	}

	public function trials()
	{

		if(!is_admin()) die('Bad Request');
		//获取所有评审信息
		$edudata = self::getEdudataInstance();
		$reviews=$edudata->get_all_reviews();
		//获取所有的评审
		$templates=$edudata->get_all_template();

		$data['reviews']=$reviews;
		$data['templates']=$templates;

		$data['css'][]="jquery-ui.css";
		$data['css'][]="jquery-ui-timepicker-addon.css";
		$data['js'][]="timepicker/jquery-ui.min.js";
		$data['js'][]="timepicker/jquery-ui-timepicker-addon.js";
		$data['js'][]="timepicker/jquery-ui-sliderAccess.js";
		$data['js'][]="timepicker/jquery-ui-timepicker-zh-CN.js";
		$data['js'][]="self.js";
		$data['title']=$data['top_title']="评审设置";
		render($data);
	}


	public function add_trial()
	{
		if(!is_admin()) die('Bad Request');
		render($data,'ajax');
	
	}

	public function doadd_trial()
	{
		if(!is_admin()) die('Bad Request');

		$review_name=z(t(v('review_name')));
		$start_time=strtotime( z(t(v('start_time'))) );
		$end_time=strtotime( z(t(v('end_time'))) );
		$status=z(t(v('status')));
		$project_type=z(t(v('project_type')));

		
		$edudata = self::getEdudataInstance();
		$review_id=$edudata->add_review($review_name,$start_time,$end_time,$status,$project_type);
		if($review_id>0)
			return ajax_echo("恭喜，添加评审成功！<script>$('#doadd_trial_btn').attr('disabled','true');location='/?a=trials';</script>");
		else
			return ajax_echo("添加失败");
	}

	public function edit_review()
	{
		if(!is_admin()) die('Bad Request');
		
		$review_id=z(t(v('rev_id')));
		$edudata = self::getEdudataInstance();
		$review=$edudata->get_review_by_id($review_id);
		$data['review']=$review;
		render($data,'ajax');
	}

	public function update_review()
	{
		if(!is_admin()) die('Bad Request');
		$review_id=z(t(v('revid')));
		$review_name=z(t(v('review_name')));
		$start_time=strtotime( z(t(v('start_time'))) );
		$end_time=strtotime( z(t(v('end_time'))) );
		$status=z(t(v('status')));
		
		$edudata = self::getEdudataInstance();
		$review_id=$edudata->update_review($review_id,$review_name,$start_time,$end_time,$status);
		if($review_id>0)
			return ajax_echo("恭喜，编辑评审成功！<script>$('#doadd_trial_btn').attr('disabled','true');location='/?a=trials';</script>");
		else
			return ajax_echo("修改失败");
	}

	public function dodelete_review()
	{
		if(!is_admin()) die('Bad Request');
		$review_id=z(t(v('reviewid')));
		
		$edudata = self::getEdudataInstance();
		$result=$edudata->delete_review($review_id);

		if($result=='ok')
			return ajax_echo("删除成功！<script>location='/?a=trials'</script>");
		else
			return ajax_echo("修改失败");


	}

	public function delete_review()
	{
		if(!is_admin()) die('Bad Request');

		$review_id=z(t(v('reviewid')));

		$data['review_id']=$review_id;
		render($data,'ajax');

	}
	
	public function groups()
	{
		if(!is_admin()) die('Bad Request');
		$review_id=z(t(v('revid')));
		$edudata = self::getEdudataInstance();
		$review=$edudata->get_review_by_id($review_id);


		$groups=$edudata->get_review_all_groups($review_id);

		$data['review']=$review;
		$data['groups']=$groups;
		$data['title']=$data['top_title']="设置分组";
		render($data);
	}

	public function add_group()
	{
		if(!is_admin()) die('Bad Request');
		$review_id=z(t(v('rev_id')));
		$data['review_id']=$review_id;
		render($data,'ajax');
	}

	public function doadd_group()
	{
		if(!is_admin()) die('Bad Request');

		$review_id=z(t(v('rev_id')));
		$group_name=z(t(v('group_name')));
		$edudata = self::getEdudataInstance();
		$group_id=$edudata->add_group($review_id,$group_name);
		
		if($group_id>0)
			return ajax_echo("添加成功<script>location='/?a=groups&revid=$review_id'</script>");
		else
			return ajax_echo("修改失败");
	
	}
	
	public function delete_group()
	{
		if(!is_admin()) die('Bad Request');

		$group_id=z(t(v('groupid')));
		$review_id=z(t(v('rev_id')));
		
		$data['group_id']=$group_id;
		$data['review_id']=$review_id;

		render($data,'ajax');


	}

	public function dodelete_group()
	{
		if(!is_admin()) die('Bad Request');
		$group_id=z(t(v('groupid')));
		$review_id=z(t(v('revid')));
		$edudata = self::getEdudataInstance();
		$result=$edudata->delete_group($group_id);
		if($result)
			return ajax_echo("删除成功<script>location='/?a=groups&revid=$review_id'</script>");
		else
			return ajax_echo("修改失败");

	}

	public function update_group()
	{
		if(!is_admin()) die('Bad Request');

		$group_id=z(t(v('groupid')));
		$review_id=z(t(v('rev_id')));
		$edudata = self::getEdudataInstance();
		$group=$edudata->get_group_by_id($group_id,$rev_id);

		$data['group']=$group;
		$data['review_id']=$review_id;
		render($data,'ajax');
	
	}

	public function doupdate_group()
	{
		if(!is_admin()) die('Bad Request');
		$group_id=z(t(v('group_id')));
		$review_id=z(t(v('rev_id')));

		$group_name=z(t(v('group_name')));
		$edudata = self::getEdudataInstance();
		$result=$edudata->update_group_by_id($group_id,$review_id,$group_name);

		if($result[0]['group_id']>0)
			return ajax_echo('更新分组名称成功！');
		else
			return ajax_echo("修改失败");

	}

	public function experts_group()
	{
		if(!is_admin()) die('Bad Request');
		$group_id=z(t(v('groupid')));
		$review_id=z(t(v('rev_id')));
		$edudata = self::getEdudataInstance();
		//评审专家，level值系统中为2
		$experts=$edudata->get_teachers_with_level(2,$review_id);
		//var_dump($experts);
		//print_r($experts);exit();
		$data['experts']=$experts;
		$data['review_id']=$review_id;
		$data['group_id']=$group_id;
		render($data,'ajax');

	}

	public function update_experts_group()
	{
		if(!is_admin()) die('Bad Request');

		$group_id=z(t(v('group_id')));
		$experts=v('experts');
		if(!empty($experts))
			$experts_arr=explode(",",$experts);
		else
			$experts_arr="NONE";

		//if(empty($experts_arr)) print_r('ddd');exit();
		//var_dump($experts_arr);exit();

		$edudata = self::getEdudataInstance();
		$result=$edudata->update_experts_group_re($group_id,$experts_arr);
		
		if($result)
			return ajax_echo("恭喜！修改成功！");
		else
			return ajax_echo("修改失败");
	
	}


	public function project_group()
	{
		if(!is_admin()) die('Bad Request');
		$group_id=z(t(v('groupid')));
		$review_id=z(t(v('rev_id')));
		$status=z(t(v('status')));
		$project_type=z(t(v('project_type')));

		$edudata = self::getEdudataInstance();

		//$status=$GLOBALS['project_status']['FIRST_TRIAL'];
		//$projects=$edudata->get_wait_for_trial_projects($status);

		//获取本次评审的项目
		$projects=$edudata->get_projects_detail_with_status_review($review_id,$status,$project_type);
		
		$data['projects']=$projects;
		$data['group_id']=$group_id;
		$data['review_id']=$review_id;

		render($data,'ajax');
	}

	public function update_project_group()
	{
		if(!is_admin()) die('Bad Request');

		$group_id=z(t(v('group_id')));
		$projects=v('projects');
		if(!empty($projects))
			$projects_arr=explode(",",$projects);
		else
			$projects_arr="NONE";
		
		$edudata = self::getEdudataInstance();
		$result=$edudata->update_project_group_re($group_id,$projects_arr);
		
		if($result)
			return ajax_echo("恭喜！修改成功！");
		else
			return ajax_echo("修改失败");

	}

	public function add_template()
	{
		if(!is_admin()) die('Bad Request');
		render($data,'ajax');
	}
	
	
	public function doadd_template()
	{
		if(!is_admin()) die('Bad Request');
		$template_name=z(t(v('template_name')));
		
		$edudata = self::getEdudataInstance();
		$result=$edudata->add_template($template_name);
		
		if($result[0]['template_id']>0)
			return ajax_echo("添加成功！<script>location='/?a=trials';</script>");
		else
			return ajax_echo("添加失败");

	}

	public function edit_template()
	{
		if(!is_admin()) die('Bad Request');
		$template_id=z(t(v('tempid')));

		$edudata = self::getEdudataInstance();
		$template_name=$edudata->get_template_name_by_id($template_id);

		$data['template_name']=$template_name;
		$data['template_id']=$template_id;
		render($data,'ajax');

	}

	public function update_template()
	{
		if(!is_admin()) die('Bad Request');
		$template_id=z(t(v('tempid')));
		$template_name=z(t(v('template_name')));

		$edudata = self::getEdudataInstance();
		$result=$edudata->update_template_name_by_id($template_id,$template_name);
		
		if($result['template_id']>0)
			return ajax_echo("修改成功！<script>location='/?a=trials';</script>");
		else
			return ajax_echo("修改失败");

	}

	public function delete_template()
	{
		if(!is_admin()) die('Bad Request');
		$template_id=z(t(v('tempid')));

		$data['template_id']=$template_id;
		render($data,'ajax');
	}

	public function dodelete_template()
	{
		if(!is_admin()) die('Bad Request');
		$template_id=z(t(v('tempid')));

		$edudata = self::getEdudataInstance();

		//这里需要补充，没有关联数据才可以删除


		$result=$edudata->delete_template_by_id($template_id);

		if($result['msg']=='ok')
			return ajax_echo("删除成功！<script>location='/?a=trials';</script>");
		else
			return ajax_echo("删除失败！");

	}

	public function template_node()
	{
		if(!is_admin()) die('Bad Request');
		$template_id=z(t(v('tempid')));

		$edudata = self::getEdudataInstance();
		$template_name=$edudata->get_template_name_by_id($template_id);

		$nodes=$edudata->get_template_all_nodes($template_id);

		$data['nodes']=$nodes;
		$data['template_name']=$template_name;
		$data['template_id']=$template_id;
		$data['top_title']=$data['title']="设置评审标准";
		render($data);

	}

	public function add_template_node()
	{
		if(!is_admin()) die('Bad Request');
		$template_id=z(t(v('tempid')));

		$data['template_id']=$template_id;
		render($data);
	}


	public function doadd_template_node()
	{
		if(!is_admin()) die('Bad Request');
		$template_id=z(t(v('tempid')));
		$node_name=z(t(v('node_name')));
		$node_description=z(t(v('node_description')));
		$node_type=z(t(v('node_type')));
		$score=z(t(v('score')));
		$content_restrict=z(t(v('content_restrict')));

		if($node_type==0 && ($score=="" || !is_numeric($score)))
			return ajax_echo("分值未填写或不为数字！");

		if($node_type==1 && ($content_restrict=="" || !is_numeric($content_restrict)))
			return ajax_echo("评论字数限制未填写或不为数字！");

		$edudata = self::getEdudataInstance();

		$result=$edudata->add_template_node($template_id,$node_name,$node_description,$node_type,$score,$content_restrict);

		if($result[0]['node_id']>0)
			return ajax_echo("添加成功！<script>location='/?a=template_node&tempid=$template_id';</script>");
		else
			return ajax_echo("删除失败！");

	}


	public function edit_template_node()
	{
		if(!is_admin()) die('Bad Request');
		$node_id=z(t(v('node_id')));

		$edudata = self::getEdudataInstance();
		$node=$edudata->get_template_node_by_id($node_id);
		$data['node_id']=$node_id;
		$data['node']=$node;
		render($data);
	}

	public function update_template_node()
	{
		if(!is_admin()) die('Bad Request');

		$node_id=z(t(v('nodeid')));
		$template_id=z(t(v('tempid')));
		$node_name=z(t(v('node_name')));
		$node_description=z(t(v('node_description')));
		$node_type=z(t(v('node_type')));
		$score=z(t(v('score')));
		$content_restrict=z(t(v('content_restrict')));
		
		$edudata = self::getEdudataInstance();
		$result=$edudata->update_template_node($node_id,$template_id,$node_name,$node_description,$node_type,$score,$content_restrict);
		if($result[0]['node_id']>0)
			return ajax_echo("修改成功！<script>location='/?a=template_node&tempid=$template_id';</script>");
		else
			return ajax_echo("删除失败！");

	}

	public function ajax_update_node_active()
	{
		if(!is_admin()) die('Bad Request');
		$node_id=z(t(v('nodeid')));
		$active=z(t(v('active')));
		$template_id=z(t(v('tempid')));

		$active=($active)?0:1;
		$edudata = self::getEdudataInstance();

		$result=$edudata->update_template_node_active($node_id,$active);

		if($result[0]['node_id']>0)
			return ajax_echo("修改成功！<script>location='/?a=template_node&tempid=$template_id';</script>");
		else
			return ajax_echo("删除失败！");
	}

	public function delete_template_node()
	{
		if(!is_admin()) die('Bad Request');
		$node_id=z(t(v('nodeid')));
		$template_id=z(t(v("tempid")));
		$data['node_id']=$node_id;
		$data['template_id']=$template_id;

		render($data,'ajax');
	}

	public function dodelete_template_node()
	{
		if(!is_admin()) die('Bad Request');
		$node_id=z(t(v('nodeid')));
		$template_id=z(t(v('template_id')));
		$edudata = self::getEdudataInstance();
		$result=$edudata->delete_template_node($node_id);
		if($result['msg']=='ok')
			return ajax_echo("删除成功！<script>location='/?a=template_node&tempid=$template_id';</script>");
		else
			return ajax_echo("删除失败！");
	}

	public function template_review()
	{
		if(!is_admin()) die('Bad Request');
		$review_id=z(t(v('revid')));
		$template_id=z(t(v('tempid')));
		$edudata = self::getEdudataInstance();
		$templates=$edudata->get_all_template();

		//获取rev_template_review_re关联数据

		//$current_template=$edudata->get_template_by_review_id($review_id);
		//var_dump($current_template);exit();

		//if(is_null($current_template) || $current_template=="")
		//	$current_template="NONE";


		$data['current_template']=$template_id;
		$data['templates']=$templates;
		$data['review_id']=$review_id;
		render($data,'ajax');
	}

	public function update_template_review()
	{
		if(!is_admin()) die('Bad Request');
		$review_id=z(t(v('revid')));
		$template_id=z(t(v('template')));

		$edudata = self::getEdudataInstance();
		$result=$edudata->update_review_template($review_id,$template_id);
		
		if($result['review_id']>0)
			return ajax_echo("修改成功！<script>location='/?a=trials';</script>");
		else
			return ajax_echo("修改失败！");
	
	}

	public function review()
	{
		if(!is_expert()) die("Bad Request");
		$review_id=z(t(v('revid')));
		$template_id=z(t(v('tmpid')));
		$qlty_current_stage=unserialize(ss('qlty_current_stage'));
/*		if( $qlty_current_stage['current_stage']=='30' || $qlty_current_stage['current_stage']=='70')
		{*/
		
			//获取该teacher的review信息，三表关联查询
			$edudata = self::getEdudataInstance();
			$teacher_id=$_SESSION['teacher']['teacher_id'];
			$teacher_reviews=$edudata->get_teacher_review_detail($teacher_id);

			//print_r($teacher_reviews);exit();

/*		}else
		{
			//不是评审时期，不能评审
			$teacher_reviews="WRONG_TIME";
		}*/
		$data['qlty_current_stage']=$qlty_current_stage;
		$data['review_id']=$review_id;
		$data['template_id']=$template_id;
		$data['teacher_reviews']=$teacher_reviews;

		$data['title']=$data['top_title']="专家评审";
		render($data);
	}

	public function review_project_list()
	{
		if(!is_expert()) die("Bad Request");

		$group_id=z(t(v('gid')));
		$review_id=z(t(v('revid')));
		$template_id=z(t(v('tmpid')));
		$se=v('se');
		//防止修改链接id
		if($se==md5("ids".$group_id.$review_id.$template_id) )
		{
			$edudata = self::getEdudataInstance();

			//此次评审的信息
			$review=$edudata->get_review_by_id($review_id);
			
			if($review['start_time']<time() && $review['end_time']>time())
			{
				//获取当前专家要评审的项目信息
				
				$projects=$edudata->get_projects_with_group_id($group_id);

				$results=$edudata->get_rev_results_detail_with_expert_id($review_id,$_SESSION['teacher']['teacher_id']);

				$unfinished_num=0;
				//用director_id来标示，因为pid合并为空了，系统中保证一个人只能申报一个项目进行评审
				$project_unfinished_arr=Array();
				$project_score_arr=array();
				foreach($results as $result)
				{
					if($result['comment']=="" && $result['point']==""){
						
						if(!Array_key_exists($result['director_id'],$project_unfinished_arr))
						{
							$project_unfinished_arr[$result['director_id']]=1;
						}else{
							$project_unfinished_arr[$result['director_id']]++;
						}
						$unfinished_num++;
					}
					if($result['node_type']=='0' )
					{
						if(!Array_key_exists($result['director_id'],$project_score_arr)){
							$project_score_arr[$result['director_id']]=($result['point']>0)?$result['point']:0;
						}else{
							$project_score_arr[$result['director_id']] +=($result['point']>0)?$result['point']:0;
						}
					}

				}

				//将projects数组组成pid为key的数组，便于按分数排序输出
				$ids_projects = array();
				foreach ($projects as $project) {
					$ids_projects[$project['director_id']]=$project;
				}

				//按照分数排序
				arsort($project_score_arr);

				//通过与暂缓的分隔线，70
				$past_point =70;

				// var_dump($review);exit();
				$data['past_point'] = $past_point;
				$data['unfinished_num']=$unfinished_num;
				$data['sum']=sizeof($results);
				$data['project_unfinished_arr']=$project_unfinished_arr;
				$data['project_score_arr']=$project_score_arr;
				$data['qlty_category']=(unserialize($_SESSION['qlty_course_category']))+(unserialize($_SESSION['qlty_project_category']))+(unserialize($_SESSION['qlty_team_category']));

				$data['qlty_rank']=unserialize($_SESSION['qlty_rank']);
				$data['qlty_specity']=unserialize($_SESSION['qlty_specity']);
				$data['projects']=$projects;
				$data['group_id']=$group_id;
				$data['ids_projects']=$ids_projects;
				$data['review']=$review;
				$data['review_id']=$review_id;
				$data['template_id']=$template_id;
				$data['title']=$data['top_title']="评审详单";
				
				render($data);
				
			}else{

				die('review disabled');
			}
		
		}else
		{
		
			die('Bad Action');
		}



	}

	public function expert_project_suggest()
	{
		$project_id =z(t(v('pid')));
		$review_id = z(t(v('review_id')));
		$group_id =z(t(v('group_id')));

		$edudata = self::getEdudataInstance();
		$results = $edudata->get_project_review_suggestion($project_id,$review_id,$group_id);
		//将建议分组
		$comment_nodes =array();
		$suggestions =array();
		foreach ($results as $result) {
			$suggestions[$result['expert_id']][$result['node_id']] = $result;
			if(!Array_key_exists($result['node_id'],$comment_nodes))
			{
				$comment_nodes[$result['node_id']]=$result['node_name'];
			}
		}

		$data['suggestions'] = $suggestions;
		$data['comment_nodes']=$comment_nodes;
		render($data,'ajax');
	
	}

	public function expert_view()
	{
		
		if(!is_expert()) die("Bad Request");
		//获取加密字符串

		$group_id=z(t(v('gid')));
		$review_id=z(t(v('revid')));
		$project_id=z(t(v('pid')));
		$template_id=z(t(v('tmpid')));
		//获取安全密串
		$se=z(t(v('se')));
		//安全性验证！
		//防止链接随意修改！

		if( $se== md5(c('key').$group_id.$project_id.$review_id.$template_id))
		{

			//获取当前用户所评审的，该项目的信息
			$edudata = self::getEdudataInstance();

			//首先获取评审模板信息
			$template_nodes=$edudata->get_template_all_nodes($template_id);
			//获取项目信息
			$user_project=$edudata->get_project_detail_with_project_id($project_id);
			//先获取当前评审的状态
			$review=$edudata->get_review_by_id($review_id);
			$asset_type=0;
			if($review['status_num']==$GLOBALS['project_status']['FIRST_TRIAL'])
			{
				//如果是校级
				// if($user_project['rank']=='0'){
				// 	$asset_type=12;
				// }else if($user_project['rank']=='2')
				// {
				// 	$asset_type=14;
				// }
				
				//2015-05-19不管是校级市级，全部显示校级申报书
				$asset_head=1;
			}
			else if($review['status_num']==$GLOBALS['project_status']['WAIT_LAST_TRIAL'])
			{
				$asset_head=6;
			}
			//获取当前评审材料
			// $asset=$edudata->get_project_assets_with_type($project_id,$asset_type);
			$qlty_assets = $edudata->get_qlty_asset_status($project_id,$user_project['director_id']);
			// var_dump($qlty_assets);exit();
			// $asset_uri=c('resource_site').$asset[0]['asset_uri'];

			//将评论与打分的node_id记录
			$node_comment_ids="";
			$node_ids="";
			$node_flag=false;
			$flag=false;
			foreach($template_nodes as $template_node)
			{
				if($node_flag) $node_ids .=",";
				$node_ids .=$template_node['node_id'];
				$node_flag=true;

				if($template_node['node_type']){
					if($flag) $node_comment_ids .=",";
					$node_comment_ids .=$template_node['node_id'];
					$flag=true;
				}
			}

			
			//获取已有的评审信息
			$current_expert_id=$_SESSION['teacher']['teacher_id'];
			$rev_results=$edudata->get_rev_results($project_id,$current_expert_id,$review_id);
			$result=Array();
			// print_r($rev_results);exit();
			if($rev_results){
				foreach($rev_results as $rev_result)
				{
					$result['comment'.$rev_result['node_id']]['comment']=$rev_result['comment'];
					$result['point'.$rev_result['node_id']]['point']=$rev_result['point'];
				}
			}
			// var_dump($result);exit();
			//数据渲染
			$data['qlty_category']=(unserialize($_SESSION['qlty_course_category']))+(unserialize($_SESSION['qlty_project_category']))+(unserialize($_SESSION['qlty_team_category']));

			$data['qlty_rank']=unserialize($_SESSION['qlty_rank']);
			$data['qlty_specity']=unserialize($_SESSION['qlty_specity']);

			$data['user_project']=$user_project;
			$data['result']=$result;
			$data['nodes']=base64_encode(serialize($template_nodes));
			$data['node_ids']=$node_ids;
			$data['node_comment_ids']=$node_comment_ids;
			$data['template_nodes']=$template_nodes;
			$data['asset_head']=$asset_head;
			$data['qlty_assets']=$qlty_assets;
			$data['group_id']=$group_id;
			$data['review_id']=$review_id;
			$data['project_id']=$project_id;
			$data['template_id']=$template_id;
			$data['title']=$data['top_title']="《".$user_project["name"]."》项目评审";
			$data['css'][]="index.css";
			$data['js'][]="scrolltop.js";
			$data['js'][]="textarea.js";
			render($data,'','expertview');
			
		}else{
			die('Bad Action');
		}


	}	

	public function new_expert_view()
	{
		//课程的评审，直接查看网站	
		if(!is_expert()) die("Bad Request");
		//获取加密字符串

		$group_id=z(t(v('gid')));
		$review_id=z(t(v('revid')));
		$project_id=z(t(v('pid')));
		$template_id=z(t(v('tmpid')));
		//获取安全密串
		$se=z(t(v('se')));
		//安全性验证！
		//防止链接随意修改！

		if( $se== md5(c('key').$group_id.$project_id.$review_id.$template_id))
		{

			//获取当前用户所评审的，该项目的信息
			$edudata = self::getEdudataInstance();

			//首先获取评审模板信息
			$template_nodes=$edudata->get_template_all_nodes($template_id);
			//获取项目信息
			$user_project=$edudata->get_project_detail_with_project_id($project_id);
			//先获取当前评审的状态
			$review=$edudata->get_review_by_id($review_id);
			$asset_type=0;
			// var_dump($template_nodes);
			if($review['status_num']==$GLOBALS['project_status']['FIRST_TRIAL'])
			{
				//如果是校级
				if($user_project['rank']=='0'){
					$asset_type=12;
				}else if($user_project['rank']=='2')
				{
					$asset_type=14;
				}
				
			}
			else if($review['status_num']==$GLOBALS['project_status']['WAIT_LAST_TRIAL'])
			{
				$asset_type=72;
			}
			//获取当前评审材料
			$asset=$edudata->get_project_assets_with_type($project_id,$asset_type);
			$asset_uri=c('resource_site').$asset[0]['asset_uri'];

			//将评论与打分的node_id记录
			$node_comment_ids="";
			$node_ids="";
			$node_flag=false;
			$flag=false;
			foreach($template_nodes as $template_node)
			{
				if($node_flag) $node_ids .=",";
				$node_ids .=$template_node['node_id'];
				$node_flag=true;

				if($template_node['node_type']){
					if($flag) $node_comment_ids .=",";
					$node_comment_ids .=$template_node['node_id'];
					$flag=true;
				}
			}

			
			//获取已有的评审信息
			$current_expert_id=$_SESSION['teacher']['teacher_id'];
			$rev_results=$edudata->get_rev_results($project_id,$current_expert_id,$review_id);
			$result=Array();
			//print_r($rev_results);exit();
			if($rev_results){
				foreach($rev_results as $rev_result)
				{
					$result['comment'.$rev_result['node_id']]['comment']=$rev_result['comment'];
					$result['point'.$rev_result['node_id']]['point']=$rev_result['point'];
				}
			}
			// var_dump($asset_uri);exit();
			//数据渲染
			$data['qlty_category']=(unserialize($_SESSION['qlty_course_category']))+(unserialize($_SESSION['qlty_project_category']))+(unserialize($_SESSION['qlty_team_category']));

			$data['qlty_rank']=unserialize($_SESSION['qlty_rank']);
			$data['qlty_specity']=unserialize($_SESSION['qlty_specity']);

			$data['user_project']=$user_project;
			$data['result']=$result;
			$data['nodes']=base64_encode(serialize($template_nodes),c('key'));
			$data['node_ids']=$node_ids;
			$data['node_comment_ids']=$node_comment_ids;
			$data['template_nodes']=$template_nodes;
			$data['asset_uri']=$asset_uri;
			$data['group_id']=$group_id;
			$data['review_id']=$review_id;
			$data['project_id']=$project_id;
			$data['template_id']=$template_id;
			$data['title']=$data['top_title']="《".$user_project["name"]."》项目评审";
			$data['css'][]="index.css";
			//$data['js'][]="scrolltop.js";
			$data['js'][]="textarea.js";
			render($data,'','newexpertview');
			
		}else{
			die('Bad Action');
		}


	}


	public function review_result()
	{
		if(!is_expert()) die("Bad Request");
		$nodes= unserialize(base64_decode( z(t(v('nodes'))) ));
		$node_ids=z(t(v('nodeids')));
		$node_comment_ids=z(t(v('commentids')));
		$review_id=z(t(v('revid')));
		$group_id=z(t(v('gid')));
		$project_id=z(t(v('pid')));
		$template_id=z(t(v('tmpid')));
		$current_expert_id=$_SESSION['teacher']['teacher_id'];
		// var_dump( $nodes);
		//组装数据
		$rev_results=Array();

		foreach($nodes as $node)
		{
			//数组与数据表中的字段对应
			if($node['node_type'])
			{	
				$comment=z(t(v('comment'.$node['node_id'])));
				$point=0;
				//最少字数检验，允许为空
				if(strlen($comment)!=0 && mb_strlen($comment,'UTF-8')<$node['content_restrict']){
					return ajax_echo("“".$node['node_name']."”节点的字数太少，最少需要".$node['content_restrict']."个字符");
				}
				
				if( $comment!="")
					$rev_results[]=Array($project_id,$current_expert_id,$review_id,$group_id,$node['node_id'],$comment,$point,$node['node_type']);
				
			}else{
				//如果是评分节点，有字数限制意味着也要填写意见

				//注意成绩都乘以了1000，最终结果的地方再除
				$point=z(t(v('point'.$node['node_id'])));
				$comment=z(t(v('comment'.$node['node_id'])));
				if($point!='-1'){
					if($node['content_restrict']>0){
						if(strlen($comment)==0 || mb_strlen($comment,'UTF-8')<$node['content_restrict']){
							return ajax_echo("“".$node['node_name']."”节点的字数太少，最少需要".$node['content_restrict']."个字符");
						}
					}else{
						$comment="";
					}
					$rev_results[]=Array($project_id,$current_expert_id,$review_id,$group_id,$node['node_id'],$comment,$point,$node['node_type']);
				}else{
					if($comment!="")
						return ajax_echo("“".$node['node_name']."”节点填写了评审意见但未打分");
				}

			}
			
			//只有评论或打分不为空时（即该节点已处理），才能插入数据
			
			// if( $comment!="" || $point>0 )
			// 	$rev_results[]=Array($project_id,$current_expert_id,$review_id,$group_id,$node['node_id'],$comment,$point);

		}
		$edudata = self::getEdudataInstance();

		//暂时没有实现修改部分，采用全部修改的方式
		//(1)先删除node_result表中  当前评审专家(teacher_id)、本次评审(review_id)、本项目(qlty_project_id)的所有信息
		//(2)重新插入所有信息
		$status=$edudata->update_rev_results($project_id,$current_expert_id,$review_id,$rev_results);

		if($status)
			return ajax_echo("修改成功！");
		else
			var_dump($status);
	}


	public function check_result()
	{
		if(!is_admin()) die("Bad Request");
		$review_id=z(t(v('revid')));
		$review_name=z(t(v('rev_name')));
		$end_time=z(t(v('endtime')));
		$expert_id=z(t(v('expert_id')));
		
		$edudata = self::getEdudataInstance();
		//这个查询基本上主要的表都涉及到了……没办法

		$results=$edudata->get_rev_results_detail($review_id);
		//print_r($results);exit();
		//获取所有教师（active）信息
		$ts=$edudata->get_all_teachers_detail();
		//将数组处理
		$teachers=Array();
		if($ts){
			foreach($ts as $t)
			{
				$teachers[$t['teacher_id']]['teacher_name']=$t['teacher_name'];
				$teachers[$t['teacher_id']]['email']=$t['email'];
				$teachers[$t['teacher_id']]['department_name']=$t['department_name'];
				$teachers[$t['teacher_id']]['mobile_phone']=decrypt($t['mobile_phone'],c('key'));
			}
		}
		
		//获取没有完成评审的专家列表
		//teacher_id=>unfinished_node_num
		$unfinished_teachers=Array();

		//汇总评审结果
		$results_summary=Array();
		$comment_nodes=Array();

		if($results)
		{
			foreach($results as $result)
			{
				//需要排除由于left join出来的不合理数据
				if($result['teacher_id']==$result['expert_id'] || is_null($result['expert_id']) )
				{
					//
					if( ($result['comment']=="" || is_null($result['comment'])) && (is_null($result['point']) ) )
					{
						if(!Array_key_exists( $result['teacher_id'] ,$unfinished_teachers) )
						{
							$unfinished_teachers[ $result['teacher_id'] ]=1;
						}else{
							$unfinished_teachers[ $result['teacher_id'] ]=$unfinished_teachers[ $result['teacher_id'] ]+1;
						}
					}
				}
				
				if(!Array_key_exists($result['qlty_project_id'],$results_summary ))
				{
					$results_summary[$result['qlty_project_id']]['director_id']=$result['director_id'];
					$results_summary[$result['qlty_project_id']]['qlty_project_id']=$result['qlty_project_id'];
					$results_summary[$result['qlty_project_id']]['name']=$result['name'];
					$results_summary[$result['qlty_project_id']]['status']=$result['status'];
					$results_summary[$result['qlty_project_id']]['status_num']=$result['status_num'];
				}

				//评审专家信息
				if(!$result['node_type'])
					$results_summary[$result['qlty_project_id']]['expert'][$result['teacher_id']]['sum'] +=$result['point'];
				else{
					$results_summary[$result['qlty_project_id']]['expert'][$result['teacher_id']]['comment'][$result['node_id']] =$result['comment'];

				}

				//主观意见的节点
				if(!Array_key_exists($result['node_id'],$comment_nodes) && $result['node_type'])
				{
					$comment_nodes[$result['node_id']]=Array(
						'node_id'=>$result['node_id'],
						'node_name'=>$result['node_name'],
						'node_description'=>$result['node_description']
					);
				}



			}//end foreach
		}
		//var_dump($results_summary);exit();

		$contact_list=Array();
		if($unfinished_teachers)
		{
			foreach($unfinished_teachers as $k=>$v){
				$contact_list[$k]=$teachers[$k];
			}
		}

		$data['end_time']=$end_time;
		$data['comment_nodes']=$comment_nodes;
		$data['results_summary']=$results_summary;
		$data['review_name']=$review_name;
		$data['contact_list']=encrypt(serialize($contact_list),c('key'));
		$data['unfinished_teachers']=$unfinished_teachers;
		$data['teachers']=$teachers;
		$data['results']=$results;
		$data['title']=$data['top_title']=$review_name."评审结果检查";
		$data['js'][]="move.js";
		$data['css'][]="result.css";
		render($data);
	}

	public function contact()
	{
		if(!is_admin()) die("Bad Request");
		$experts=z(t(v('experts')));
		$contact_list=unserialize( decrypt(z(t(v('contact_list'))),c('key')) );
		$end_time=z(t(v('end_time')));
		$send_sms=z(t(v('send_sms')));
		
		//组装Email

		if(!is_null($contact_list) && $experts!="")
		{
			$experts_arr=explode(",",$experts);

			foreach($experts_arr as $tid)
			{
				
				$subject="您的评审项目尚未全部完成";
				$content="尊敬的".$contact_list[$tid]['teacher_name']."：<br><br>"
						."您的评审项目并未全部完成评审，请登录质量工程信息系统完成评审（点击此链接<a href='http://zlgc.cqtbi.edu.cn/'>http://zlgc.cqtbi.edu.cn/</a>）<br><br>"
						."此邮件由系统自动发出，请勿回复。如有疑问，欢迎咨询教务处项目科42861081";
				$result="";
				$send_email_result=send_mail( $contact_list[$tid]['email'] , $subject , $content );
				$result=json_decode($send_email_result);
					//var_dump($result);
				if($result->message=='success')
					$result="邮件发送成功";
				else
					$result="邮件发送失败";

				if($send_sms=="on")
				{
					$content="尊敬的".$contact_list[$tid]['teacher_name']."您好，您评审项目没有全部完成，请您访问质量工程信息系统在".date("m-d H:i",$end_time)."前完成评审。【质量工程网】";
					$send_sms_result=send_sms($contact_list[$tid]['mobile_phone'],$content);
					if($send_sms_result=='1')
						$result .="短信已发送成功<br>";
					else
						$result .=$send_sms_result."短信发送失败";
				}

			}

			return ajax_echo($result."<script>$('#pass_message_btn').attr('disabled','true');</script>");

		}else{
			return ajax_echo("请选择需要通知的专家");
			
		}


	}

	public function ajax_update_project_status()
	{
		if(!is_admin()) die("Bad Request");
		$qlty_project_id=z(t(v('pid')));
		$director_id=z(t(v('directorid')));
		$status_num=z(t(v('status_num')));
		$pass=z(t(v('pass')));

		if($status_num==$GLOBALS['project_status']['FIRST_TRIAL'])
		{
			if($pass)
				$status=$GLOBALS['project_status']['ESTABLISHED'];
			else
				$status=$GLOBALS['project_status']['REJECTED'];
		}
		else if($status_num==$GLOBALS['project_status']['WAIT_LAST_TRIAL'])
		{
			if($pass)
				$status=$GLOBALS['project_status']['DONE'];
			else
				$status=$GLOBALS['project_status']['NEXT_TURN'];
		}
		
		$edudata = self::getEdudataInstance();
		$result=$edudata->update_project_status($qlty_project_id,$director_id,$status);
		if($result)
		{
			if($status==$GLOBALS['project_status']['ESTABLISHED'])
			{
				$r=$edudata->update_project_apply_established_time($qlty_project_id,$director_id);
			}
			if($status==$GLOBALS['project_status']['DONE'])
			{
				$r=$edudata->update_project_done_time($qlty_project_id,$director_id);
			}

			return ajax_echo("修改成功！正在转向……<script>location.reload();</script>");
		}

	}


	public function result_feedback()
	{
		if(!is_admin()) die("Bad Request");
		$director_id=z(t(v('director_id')));
		$email=z(t(v('email')));
		$teacher_name=z(t(v('teacher_name')));
		$mobile_phone=z(t(v('mobile_phone')));
		$project_name=urldecode(z(t(v('project_name'))));
		$project_id=z(t(v('pid')));
		$status=z(t(v('status')));

		$m="";
		if($status==$GLOBALS['project_status']['ESTABLISHED'])
		{
			$m="立项成功";
		}else if($status==$GLOBALS['project_status']['REJECTED'])
		{
			$m="立项失败";
		}


		$content="尊敬的".$teacher_name."：<br><br>"
				."您的《".$project_name."》项目".$m."，请登录质量工程信息系统查看评审意见。<br>"
				."本信息由系统自动发出，请勿回复。【质量工程】";
		
		$data['content']=$content;
		$data['director_id']=$director_id;
		$data['email']=$email;
		$data['teacher_name']=$teacher_name;
		$data['mobile_phone']=$mobile_phone;
		$data['project_name']=$project_name;
		$data['project_id']=$project_id;

		render($data);
	}

	public function message()
	{
		if(!is_admin()) die("Bad Request");
		$director_id=z(t(v('tid')));
		$email=z(t(v('email')));
		$teacher_name=z(t(v('teacher_name')));
		$mobile_phone=z(t(v('mobile_phone')));
		$project_name=z(t(v('project_name')));
		$project_id=z(t(v('pid')));
		$content=z(t(v('content')));
		$send_sms=z(t(v('send_sms')));

		//组装Email
		$subject="项目状态更改";

		$result="";
		$send_email_result=send_mail( $email , $subject , $content );
		$result=json_decode($send_email_result);
			//var_dump($result);
		if($result->message=='success')
			$result="邮件发送成功";
		else
			$result="邮件发送失败";

		if($send_sms=="on")
		{
			$send_sms_result=send_sms($mobile_phone,$content);
			if($send_sms_result=='1')
				$result .="短信已发送成功<br>";
			else
				$result .="短信发送失败";
		}

		
		return ajax_echo($result."<script>$('#message_btn').attr('disabled','true');</script>");


	}

	public function teacher_result()
	{
		$project_id=z(t(v('pid')));
		$teacher_id=z(t(v('tid')));

		if($teacher_id !=$_SESSION['teacher']['teacher_id'])
			die("Bad Request");

		$edudata = self::getEdudataInstance();

		//获取review_id
		$review_id=$edudata->get_review_id_by_project_id($project_id);

		//这个查询基本上主要的表都涉及到了……没办法

		$results=$edudata->get_rev_results_detail($review_id);
		//print_r($results);exit();
		//获取所有教师（active）信息
		$ts=$edudata->get_all_teachers_detail();
		//将数组处理
		$teachers=Array();
		if($ts){
			foreach($ts as $t)
			{
				$teachers[$t['teacher_id']]['teacher_name']=$t['teacher_name'];
				$teachers[$t['teacher_id']]['email']=$t['email'];
				$teachers[$t['teacher_id']]['department_name']=$t['department_name'];
				$teachers[$t['teacher_id']]['mobile_phone']=decrypt($t['mobile_phone'],c('key'));
			}
		}
		
		//获取没有完成评审的专家列表
		//teacher_id=>unfinished_node_num


		//汇总评审结果
		$results_summary=Array();
		$comment_nodes=Array();

		if($results)
		{
			foreach($results as $result)
			{
				
				if(!Array_key_exists($result['qlty_project_id'],$results_summary ))
				{
					$results_summary[$result['qlty_project_id']]['director_id']=$result['director_id'];
					$results_summary[$result['qlty_project_id']]['qlty_project_id']=$result['qlty_project_id'];
					$results_summary[$result['qlty_project_id']]['name']=$result['name'];
					$results_summary[$result['qlty_project_id']]['status']=$result['status'];
					$results_summary[$result['qlty_project_id']]['status_num']=$result['status_num'];
				}

				//评审专家信息
				if(!$result['node_type'])
					$results_summary[$result['qlty_project_id']]['expert'][$result['teacher_id']]['sum'] +=$result['point'];
				else{
					$results_summary[$result['qlty_project_id']]['expert'][$result['teacher_id']]['comment'][$result['node_id']] =$result['comment'];

				}

				//主观意见的节点
				if(!Array_key_exists($result['node_id'],$comment_nodes) && $result['node_type'])
				{
					$comment_nodes[$result['node_id']]=Array(
						'node_id'=>$result['node_id'],
						'node_name'=>$result['node_name'],
						'node_description'=>$result['node_description']
					);
				}



			}//end foreach
		}
		//var_dump($results_summary);exit();


		$data['comment_nodes']=$comment_nodes;
		$data['results_summary']=$results_summary;
		$data['review_name']=$review_name;
		$data['my_project_id']=$project_id;

		$data['teachers']=$teachers;
		$data['results']=$results;
		$data['title']=$data['top_title']=$review_name."评审结果检查";
		$data['js'][]="move.js";
		$data['css'][]="result.css";
		render($data);
	}

	public function expert_view_test()
	{
		
		if(!is_expert()) die("Bad Request");
		//获取加密字符串

		$group_id=z(t(v('gid')));
		$review_id=z(t(v('revid')));
		$project_id=z(t(v('pid')));
		$template_id=z(t(v('tmpid')));
		//获取安全密串
		$se=z(t(v('se')));
		//安全性验证！
		//防止链接随意修改！

		if( $se== md5(c('key').$group_id.$project_id.$review_id.$template_id))
		{

			//获取当前用户所评审的，该项目的信息
			$edudata = self::getEdudataInstance();

			//首先获取评审模板信息
			$template_nodes=$edudata->get_template_all_nodes($template_id);
			//获取项目信息
			$user_project=$edudata->get_project_detail_with_project_id($project_id);
			//先获取当前评审的状态
			$review=$edudata->get_review_by_id($review_id);
			$asset_type=0;
			if($review['status_num']==$GLOBALS['project_status']['FIRST_TRIAL'])
			{
				$asset_type=12;
			}
			else if($review['status_num']==$GLOBALS['project_status']['WAIT_LAST_TRIAL'])
			{
				$asset_type=72;
			}
			//获取当前评审材料
			$asset=$edudata->get_project_assets_with_type($project_id,$asset_type);
			$asset_uri=c('resource_site').$asset[0]['asset_uri'];


			//将评论与打分的node_id记录
			$node_comment_ids="";
			$node_ids="";
			$node_flag=false;
			$flag=false;
			foreach($template_nodes as $template_node)
			{
				if($node_flag) $node_ids .=",";
				$node_ids .=$template_node['node_id'];
				$node_flag=true;

				if($template_node['node_type']){
					if($flag) $node_comment_ids .=",";
					$node_comment_ids .=$template_node['node_id'];
					$flag=true;
				}
			}

			
			//获取已有的评审信息
			$current_expert_id=$_SESSION['teacher']['teacher_id'];
			$rev_results=$edudata->get_rev_results($project_id,$current_expert_id,$review_id);
			$result=Array();
			//print_r($rev_results);exit();
			if($rev_results){
				foreach($rev_results as $rev_result)
				{
					$result["nodeid".$rev_result['node_id']]['comment']=$rev_result['comment'];
					$result["nodeid".$rev_result['node_id']]['point']=$rev_result['point'];
				}
			}
			
			//数据渲染
			$data['qlty_category']=(unserialize($_SESSION['qlty_course_category']))+(unserialize($_SESSION['qlty_project_category']))+(unserialize($_SESSION['qlty_team_category']));

			$data['qlty_rank']=unserialize($_SESSION['qlty_rank']);
			$data['qlty_specity']=unserialize($_SESSION['qlty_specity']);

			$data['user_project']=$user_project;
			$data['result']=$result;
			$data['nodes']=encrypt(serialize($template_nodes),c('key'));
			$data['node_ids']=$node_ids;
			$data['node_comment_ids']=$node_comment_ids;
			$data['template_nodes']=$template_nodes;
			$data['asset_uri']=$asset_uri;
			$data['group_id']=$group_id;
			$data['review_id']=$review_id;
			$data['project_id']=$project_id;
			$data['template_id']=$template_id;
			$data['title']=$data['top_title']="《".$user_project["name"]."》项目评审";
			$data['css'][]="index.css";
			$data['js'][]="scrolltop.js";
			render($data,'','expertviewtest');
			
		}else{
			die('Bad Action');
		}


	}

	public function applyfund()
	{
		//获取可以报账的项目及剩余经费列表
		$tid=$_SESSION['teacher']['teacher_id'];

		$edudata = self::getEdudataInstance();
		//主研项目报账信息
		$project_funds = $edudata->get_project_funds($tid);
		$participant_project_funds=$edudata->get_participant_project_funds($tid);
		$director_funds=Array();
		$participant_funds=Array();
		if($project_funds){
			foreach ($project_funds as $p) {
				$sign_fund=$edudata->get_project_sum_fund($p['qlty_project_id']);
				$director_funds[]= $p+Array('sign_fund'=>$sign_fund['sum_fund']);
			}
		}

		if($participant_project_funds){
			foreach ($participant_project_funds as $pp) {
				$p_sign_fund=$edudata->get_project_sum_fund($pp['qlty_project_id']);
				$participant_funds[]= $pp+Array('sign_fund'=>$p_sign_fund['sum_fund']);
			}
		}

		//print_r($project_funds);
		$data['director_funds']=$director_funds;
		$data['participant_funds']=$participant_funds;
		$data['qlty_category']=(unserialize($_SESSION['qlty_course_category']))+(unserialize($_SESSION['qlty_project_category']))+(unserialize($_SESSION['qlty_team_category']));
		$data['title']=$data['top_title']="项目经费报销";
		render($data);
	}

	public function ajax_add_fund_record()
	{
		$project_id=z(t(v('pid')));
		if($project_id) 
			$pid=$project_id;
		else
			return ajax_echo("项目id丢失！");
		//项目总经费
		$project_funds=z(t(v('f')));
		//项目已申报的经费
		$sum_fund=z(t(v('sf')));
		//安全验证串
		$se=z(t(v('se')));

		if(md5('pid'.$pid.'f'.$project_funds)==$se)
		{
			//检查是否有未报销的记录单
			$edudata = self::getEdudataInstance();
			$unsign_fund=$edudata->get_unsign_fund_with_project_id($pid);
			//print_r($unsign_fund);
			$alert_str="";
			if($unsign_fund['fund_id']>0)
			{
				if($unsign_fund['director_checked']=='0')
					$alert_str="<i class='icon-warning-sign'></i><b>此项目有资金报销单项目主持人未审核，请自行提醒主持人尽快处理！</b>";
				elseif ($unsign_fund['director_checked']=='1')
					$alert_str="<i class='icon-warning-sign'></i><b>此项目有资金报销单未签字报销，请尽快报销！</b>";
			}
			//不限制为一次
			//从数据库中再sum最新的报销记录
			$tid=$_SESSION['teacher']['teacher_id'];
			$project_sum_fund = $edudata->get_project_sum_fund($pid);
			$project=$edudata->get_project_detail_with_project_id($pid);

			$qlty_category=(unserialize($_SESSION['qlty_course_category']))+(unserialize($_SESSION['qlty_project_category']))+(unserialize($_SESSION['qlty_team_category']));
			$qlty_rank=unserialize($_SESSION['qlty_rank']);

			$data['alert_str']=$alert_str;
			$data['fund_title']="《".$project['name']."》".$qlty_rank[$project['rank']].$qlty_category[$project['category']];
			$data['project_id']=$pid;
			$data['project_funds']=$project_funds;
			$data['project_sum_fund']=$project_sum_fund['sum_fund'];
			render($data,'ajax');


		}else{
			die('Bad Request');
		}

	}

	public function doadd_fund_record()
	{
		$project_id=z(t(v('pid')));
		if($project_id)
			$pid=$project_id;
		$project_funds=z(t(v('pf')));
		if($project_funds)
			$project_funds=decrypt($project_funds,c('key'));
		$fund_title=z(t(v('fund_title')));
		if($fund_title=="") 
			return ajax_echo("报销名称不能为空<script>$('#doadd_fund_record_btn').removeAttr('disabled');</script>");
		$fund_content=z(t(v('fund_content')));
		if($fund_content=="")
			return ajax_echo("报销内容不能为空<script>$('#doadd_fund_record_btn').removeAttr('disabled');</script>");
		$fund_num=z(t(v('fund_num')));
		if($fund_num=="") return ajax_echo("报销金额不能为空<script>$('#doadd_fund_record_btn').removeAttr('disabled');</script>");

		if(!preg_match("/^[1-9]{1}[0-9]*$|([1-9]{1}[0-9]*+.[0-9]*)$/",$fund_num))
			return ajax_echo("资金格式有误！只能填写数字！<script>$('#doadd_fund_record_btn').removeAttr('disabled');</script>");
		//print_r($project_funds);

		$tid=$_SESSION['teacher']['teacher_id'];
		$edudata = self::getEdudataInstance();
		$project_detail=$edudata->get_project_detail_with_project_id($pid);
		$is_director=($project_detail['director_id']==$tid)?1:0;
		$project_sum_fund = $edudata->get_project_apply_sum_fund($pid);

		$sum_fund=($project_sum_fund['sum_fund']==0 || is_null($project_sum_fund))?0:$project_sum_fund['sum_fund'];
		//print_r($sum_fund);
		//var_dump($project_detail);
		//float，检查本次申请资金是否超出(教改项目有10%的管理费，但委托项目代码4不在其中)
		$max_fund=($project_detail['type']=='xm' && $project_detail['category']!='14')?($project_detail['apply_funds']*9000):($project_detail['apply_funds']*10000);

		if(bccomp($sum_fund+$fund_num, $max_fund,0)==1)
		{
			return ajax_echo("经费总额超出".$max_fund."元！请检查数据！<script>$('#doadd_fund_record_btn').removeAttr('disabled');</script>");
		}else{
			//资金正常，记录数据库

			$params=Array(
				'qlty_project_id'=>$pid,
				'fund_title'=>$fund_title,
				'fund_content'=>$fund_content,
				'teacher_id'=>$tid,
				'fund_num'=>$fund_num,
				'time'=>time(),
				'director_checked'=>$is_director
				);
			$result=$edudata->add_project_fund_record($params);
			if($result['fund_id']>0)
			{
				//增加成功
				//若是主持人，则跳转至下载页面
				if($tid==$project_detail['director_id'])
				{
					return ajax_echo(
						"请下载并自行打印报账记录凭单！<script>location='/?a=generate_pdf_ticket&fundid=".$result['fund_id']."';</script>"
						);					
				}else{
					return ajax_echo("添加报账单成功！<br>请尽快提醒项目主持人审核此报账单！<br>审核后再下载自行打印报账!<script>$('#divStatus').load('/?a=generate_pdf_ticket&fundid=".$result['fund_id']."');</script>");
				}

			}else{
				return ajax_echo("添加失败！");
			}

		
		}
	}

	public function generate_pdf_ticket()
	{
		$fundid=z(t(v('fundid')));
		//安全检查
		$edudata = self::getEdudataInstance();
		$results=$edudata->get_fund_record_detail($fundid);
		$fund=$results[0];
		if($fund['teacher_id']==$_SESSION['teacher']['teacher_id'] && is_null($fund['ticket_url']))
		{
			//用户确认并且还未生成PDF，允许操作

			//获取报账人信息
			$teacher_name=$_SESSION['teacher']['teacher_name'];
			$fund_title=$fund['fund_title'];
			$fund_content=$fund['fund_content'];
			$fund_time=$fund['time'];
			$fund_num=$fund['fund_num'];

			//取出项目的基本信息
			$project=$edudata->get_project_detail_with_project_id($fund['qlty_project_id']);
			$project_name=$project['name'];
			$project_NO=$project['NO'];
			//已记录报销的项目经费
			//$project_sum_fund = $edudata->get_project_sum_fund($fund['qlty_project_id']);

			//报账归类
			$fund_pre = array(
					"xm"=>"教研教改",
					"kc"=>"课程建设",
					"tm"=>"教学团队",
					"cx"=>"专业建设"
				);

			//已记录申请报销的经费
			$project_sum_fund = $edudata->get_project_apply_sum_fund($fund['qlty_project_id']);
			//未报销的项目经费
			$unsubmit_fund_sum=$project['apply_funds']*10000-$project_sum_fund['sum_fund'];

			$unsubmit_fund=($project['type']=='xm')?($unsubmit_fund_sum-$project['apply_funds']*1000):$unsubmit_fund_sum;

			$qlty_category=(unserialize($_SESSION['qlty_course_category']))+(unserialize($_SESSION['qlty_project_category']))+(unserialize($_SESSION['qlty_team_category']));
			$qlty_rank=unserialize($_SESSION['qlty_rank']);

			$category=$qlty_category[$project['category']];
			$rank=$qlty_rank[$project['rank']];
			//二维码

			$qrcode=c('site_domain').'?a=check_qrcode&f='.$fundid.'&t='.$fund['teacher_id'].'&p='.$fund['qlty_project_id'].'&se='.md5('f'.$fundid.'t'.$fund['teacher_id'].'p'.$fund['qlty_project_id']);


			require_once(AROOT . 'lib' .DS. 'html2pdf'.DS.'html2pdf.class.php');
		    ob_start();

		    include(AROOT.'lib'.DS.'html2pdf'.DS.'examples'.DS.'fundticket.php');
		    $content = ob_get_clean();

		    // convert

		    try
		    {
		        $html2pdf = new HTML2PDF('P', 'A4', 'en', true, 'UTF-8', 0);
		        $html2pdf->pdf->SetDisplayMode('fullpage');
		        //$html2pdf->pdf->SetFont('droidsansfallback', '', 20);
		        $html2pdf->SetDefaultFont('droidsansfallback');
		        $html2pdf->writeHTML($content);
		        /*
		        *Output默认生成的pdf在网站的根目录
		        *我将其移动到了/static/pdf/目录下并写入数据
		        *2013-12-03
		        */
		        $oldname='ticket.pdf';
		        $html2pdf->Output($oldname,'FD');

				//move file to /static/pdf ,huangXiaodong,2013-12-03
		        if(file_exists($oldname))
		        {
		        	//$newname='static/pdf/'.date('YmdHis',time()).rand(1000,9999).'.pdf';
		        	$dir='static/pdf/'.date('Y',time()).'/'.date('m',time()).'/';
		        	if(!file_exists($dir))
		        	{
		        		@mkdir($dir);
		        	}
		        	
		        	$newname=$dir.date('YmdHis',time()).rand(1000,9999).'.pdf';
		        	//rename('ticket.pdf', $newname);
		        	$result=move_file($oldname,$dir,$newname);
		        	if($result){
		        		$edudata = self::getEdudataInstance();
		        		$result=$edudata->update_fund_ticket_url($fundid,$newname);
		        		if($result['fund_id']>0 && $project['director_id']==$_SESSION['teacher']['teacher_id']){
		        			//写入数据库成功！并且当前用户是项目主持人！提出下载！
							file_pop_download($newname);

						}
					}
		        }

		    }
		    catch(HTML2PDF_exception $e) {
		        var_dump($e);
		        exit;
		    }

		}else{
			//非法操作！
			die('Bad Request');
		}

	}

	public function project_fund_record()
	{
		$project_id=z(t(v('pid')));
		if($project_id) 
			$pid=$project_id;
		else
			return ajax_echo("项目id丢失！");

		$edudata=self::getEdudataInstance();
		$records=$edudata->get_fund_records_teacher_with_project_id($pid);
		//print_r($records);
		$data['records']=$records;
		render($data,'ajax');
	}

	public function download_file()
	{
		$fundid=z(t(v('fundid')));
		if($fundid=="")
			return ajax_echo("非法经费id");
		$fundid=decrypt(z(t(v('fundid'))),c('key'));
		$edudata = self::getEdudataInstance();
		$record=$edudata->get_fund_record_detail($fundid);

		if($record)
		{
			//直接提供下载
			file_pop_download($record[0]['ticket_url']);

		}else{
			return ajax_echo("没有记录！");
		}


	}

	public function check_qrcode()
	{
			//$qrcode=c('site_domain').'?a=check_qrcode&f='.encrypt($fundid,c('key')).'&t='.encrypt($fund['teacher_id'],c('key')).'&p='.encrypt($fund['qlty_project_id'],c('key')).'&se='.md5('f'.$fundid.'t'.$fund['teacher_id'].'p'.$fund['qlty_project_id']);
		$fund_id=z(t(v('f')));
		if($fund_id=="")
			return ajax_echo("参数为空，此链接不合法！");
		$teacher_id=z(t(v('t')));
		if($teacher_id=="")
			return ajax_echo("参数为空，此链接不合法！");
		$project_id=z(t(v('p')));
		if($project_id=="")
			return ajax_echo("参数为空，此链接不合法！");
		$se=z(t(v('se')));
		if($se=="")
			return ajax_echo("参数为空，此链接不合法！");
		// var_dump($fund_id);
		// var_dump($teacher_id);
		// var_dump($project_id);
		//拼接验证
		if(md5('f'.$fund_id.'t'.$teacher_id.'p'.$project_id)==$se)
		{
			//字符串均为正确，查询数据并显示
			$edudata=self::getEdudataInstance();
			$results=$edudata->get_fund_record_detail($fund_id);
			//本次凭单的报销信息

			$fund=$results[0];
			if($fund['sign']){
				$data['title']=$data['top_title']="报账单已被确认！";
			}else{
				//报销人信息
				$teacher=$edudata->get_teacher_info_with_id($teacher_id);
				//报销项目信息,需要获取主持人信息
				$project=$edudata->get_project_detail_with_project_id($project_id);

				//$director=$edudata->get_teacher_info_with_id($project['director_id']);
				//已记录报销的项目经费
				$project_sum_fund=$edudata->get_project_sum_fund($fund['qlty_project_id']);

				//$unsubmit_fund=$project['apply_funds']*10000-$project_sum_fund['sum_fund'];
				$unsubmit_fund_sum=$project['apply_funds']*10000-$project_sum_fund['sum_fund'];

				$unsubmit_fund=($project['type']=='xm')?($unsubmit_fund_sum-$project['apply_funds']*1000):$unsubmit_fund_sum;
				$teacher_role="项目主持人";
				if($teacher_id !=$project['director_id'])
				{
					$teacher_role="项目参与人";
				}

				$data['encrypt_fund_id']=$fund_id;
				$data['unsubmit_fund']=$unsubmit_fund;
				$data['teacher']=$teacher;
				$data['teacher_role']=$teacher_role;
				$data['project']=$project;	
				$data['title']=$data['top_title']="报销凭单验证";			
			}
			$data['fund']=$fund;

			render($data,'mobile','qrcode');


		}else{
			die('Bad Action!');
		}


	}

	public function sign_confirmation()
	{
		$fund_id=z(t(v('fundid')));
		if($fund_id=="")
			return ajax_echo("项目id丢失！");

		//扫描凭单确认时的弹出对话框
		$data['encrypt_fund_id']=$fund_id;
		$data['title']=$data['top_title']="报销确认";
		render($data,'mobile','qrcode');
	}

	public function fund_ticket_singed_in()
	{
		$fund_id=z(t(v('fundid')));
		$email=z(t(v('email')));
		$pwd=z(t(v('pwd')));
		$sign_comment=z(t(v('sign_comment')));
		if($fund_id=="")
			return ajax_echo("项目id丢失！<script>history.back();</script>");
		$edudata=self::getEdudataInstance();
		$sign_leader_id=NULL;
		if(!is_leader()){
			if($pwd==""||is_null($pwd))
			return ajax_echo("密码不能为空<script>history.back();</script>");
			//检查是否为报账审批权限
			$result=$edudata->fund_sign_verify($email,$pwd);
			if($result['err_code']==0)
			{
				//验证成功
				if($result['data']['level']!=3)
					return ajax_echo("此用户没有项目报账审批权限！");
				$sign_leader_id=$result['data']['teacher_id'];

			}else{
				return ajax_echo($result['err_code'].$result['err_msg']."<script>history.back();</script>");
			}
		}else{
			$sign_leader_id=$_SESSION['teacher']['teacher_id'];
		}

		$result=$edudata->update_fund_sign_status($fund_id,$sign_comment,$sign_leader_id);
		if($result['fund_id']>0)
		{
			/*
			发送短信通知
			*/
					
			return ajax_echo("<script>location='/?a=ticket_signed'</script>");
		}
	}

	public function ticket_signed()
	{
		$data['title']=$data['top_title']="确认成功";
		render($data,'mobile','qrcode');
	}

	public function check_participant_fund()
	{
		$project_id=z(t(v('pid')));
		if($project_id) 
			$pid=$project_id;
		else
			return ajax_echo("项目id丢失！");

		$edudata=self::getEdudataInstance();
		//确认为项目的负责人
		$project=$edudata->get_project_detail_with_project_id($pid);
		if($project['director_id']==$_SESSION['teacher']['teacher_id'])
		{
			$record=$edudata->get_fund_unchecked_by_direcotr($pid);
			if(!$record)
				return ajax_echo("没有需要审核的项目成员报销申请！");
			//已记录报销的项目经费
			$project_sum_fund = $edudata->get_project_sum_fund($pid);
			//剩余的项目经费
			$unsubmit_fund=$project['apply_funds']*10000-$project_sum_fund['sum_fund'];
			$data['unsubmit_fund']=$unsubmit_fund;
			$data['record']=$record;
			render($data,'ajax');
		}else{
			die('OOPS! IS NOT DIRECTOR!');
		}
		
	}

	public function update_director_checked()
	{
		$fid=z(t(v('fid')));
		if($fid=="")
			return ajax_echo("id丢失！");
		else
			$fund_id=decrypt($fid,c('key'));
		$pass=z(t(v('p')));
		if($pass==1 || $pass==2)
		{
			//更新状态
			$edudata=self::getEdudataInstance();
			$result=$edudata->update_director_checked($fund_id,$pass);
			if($fund_id==$result['fund_id'])
			{
				return ajax_echo("修改成功！正在转向……<script>location='/?a=applyfund';</script>");
			}

		}else{
			die('Bad Action director check');
		}
	}

	public function leader_sign()
	{
		if(!is_leader())
			die("IS NOT A Leader!");
		$edudata=self::getEdudataInstance();
		$count=10000;
		$funds_detail=$edudata->get_fund_records($count);
		$funds=array_reverse($funds_detail);

		$teachers=$edudata->get_all_teacher_info();

		$dept_arr=$_SESSION['department'];
		$department=array();
		foreach ($dept_arr as $dept) {
			$department[$dept['department_id']]=$dept['department_name'];
		}

		$all_teachers=array();
		foreach($teachers as $teacher)
		{
			$all_teachers[$teacher['teacher_id']]=array(
				"teacher_name"=>$teacher['teacher_name'],
				"professional_title"=>$teacher['professional_title'],
				'department_name'=>$department[$teacher['department_id']]
				);
		}

		$data['funds']=$funds;
		$data['all_teachers']=$all_teachers;
		$data['title']=$data['top_title']="项目资金报销审批";
		$data['js'][]="jquery.dataTables.min.js";
		$data['js'][]="funddata.js";
		$data['css'][]="jquery.dataTables.css";
		render($data);
	}

	public function check_fundid()
	{
		if(!is_leader)
			die("IS NOT A Leader!");
		$fundid=z(t(v('fundid')));
		//var_dump($fundid);
		if($fundid==""||is_null($fundid))
			return ajax_echo("请按照图片中的提示输入报账单号");
		if(!is_numeric($fundid))
			return ajax_echo("请输入\"NO\"后面的数字");
		$edudata=self::getEdudataInstance();
		$result=$edudata->get_fund_record_detail($fundid);
		//var_dump($result);
		if($result)
		{
			$fund=$result[0];
			$qrcode_link=c('site_domain').'?a=check_qrcode&f='.$fundid.'&t='.$fund['teacher_id'].'&p='.$fund['qlty_project_id'].'&se='.md5('f'.$fundid.'t'.$fund['teacher_id'].'p'.$fund['qlty_project_id']);
			//$ticket_url=c('site_domain').$fund['ticket_url'];
			return ajax_echo("已找到此报账单信息，正在打开……<script>location='".$qrcode_link."';</script>");
		}else{
			return ajax_echo("没有查到单号为".$fundid."的报账单！");
		}

	}

	public function leader_sign_view()
	{
		if(!is_leader())
			die("IS NOT A Leader!");
		$data['title']=$data['top_title']="项目资金报销审批";
		render($data);
	}

	public function admin_edit_status()
	{
		if(!is_admin())
			die("IS NOT A administrator!");
		$edudata=self::getEdudataInstance();
		$projects=$edudata->get_all_projects_detail();

		$data['qlty_category']=(unserialize($_SESSION['qlty_course_category']))+(unserialize($_SESSION['qlty_project_category']))+(unserialize($_SESSION['qlty_team_category']));

		$data['qlty_rank']=unserialize($_SESSION['qlty_rank']);
		$data['projects']=$projects;
		$data['status_meaning']=array_flip($GLOBALS['project_status']);
		$data['title']=$data['top_title']="质量工程数据勘误修改";
		$data['js'][]="jquery.dataTables.min.js";
		$data['js'][]="pdata.js";
		$data['css'][]="jquery.dataTables.css";
		//$data['js'][]="bootstrap-dropdown.js";
		render($data);
	}

	public function admin_check()
	{
		if(!is_admin())
			die("IS NOT A administrator!");
		$edudata=self::getEdudataInstance();
		$projects=$edudata->get_all_projects_detail();

		$data['qlty_category']=(unserialize($_SESSION['qlty_course_category']))+(unserialize($_SESSION['qlty_project_category']))+(unserialize($_SESSION['qlty_team_category']));

		$data['qlty_rank']=unserialize($_SESSION['qlty_rank']);
		$data['projects']=$projects;
		$data['status_meaning']=array_flip($GLOBALS['project_status']);

		$data['title'] = $data['top_title'] = "检查项目数据";
		$data['css'][] = "jquery.dataTables.css";
		$data['css'][] = "datatables.bootstrap.min.css";
		// $data['css'][]="angular/vendor/backtotop/backtotop.min.css";
		// $data['js'][]= "angular/vendor/angular/angular.min.js";
		// $data['js'][]= "jquery.dataTables.min.js";
		// $data['js'][]="angular/vendor/backtotop/backtotop.min.js";
		// $data['js'][]= "angular-datatables.min.js";
		// $data['js'][]="angular/vendor/datatables-colvis/js/dataTables.colVis.js";
		// $data['js'][]="angular/vendor/datatables-tabletools/js/dataTables.tableTools.js";
		// $data['js'][]="angular/vendor/angular-bootstrap/ui-bootstrap.min.js";
		// $data['js'][]="angular/vendor/angular-bootstrap/ui-bootstrap-tpls.min.js";
		// $data['js'][]="angular/src/angular-datatables.util.js";
		// $data['js'][]="angular/src/angular-datatables.options.js";
		// $data['js'][]="angular/src/angular-datatables.factory.js";
		// $data['js'][]="angular/src/angular-datatables.renderer.js";
		// $data['js'][]="angular/src/angular-datatables.bootstrap.options.js";
		// $data['js'][]="angular/src/angular-datatables.bootstrap.js";
		// $data['js'][]="angular/src/angular-datatables.directive.js";


		$data['js'][]= "adminCheckController.js";
		$data['v3bootstrap']=TRUE;
		render($data,'','data');
	}

	public function ajax_update_project_fund()
	{
		if(!is_admin())
			die("IS NOT A administrator!");
		$pid=z(t(v('pid')));
		if($pid==""||!is_numeric($pid))
		{
			return ajax_echo("pid丢失！");
		}
		$data['pid']=$pid;
		render($data,'ajax');
	}

	public function ajax_update_status()
	{
		if(!is_admin())
			die("IS NOT A administrator!");
		$pid=z(t(v('pid')));
		if($pid==""||!is_numeric($pid))
		{
			return ajax_echo("pid丢失！");
		}
		$data['pid']=$pid;
		render($data,'ajax');
	}

	public function doupdate_project_fund()
	{
		if(!is_admin())
			die("IS NOT A administrator!");
		$pid=z(t(v('pid')));
		$fund=z(t(v('fund')));
		if($pid==""||!is_numeric($pid))
		{
			return ajax_echo("pid丢失！");
		}
		if($fund==""||is_null($fund)) return ajax_echo("资金不能为空！");

		$edudata=self::getEdudataInstance();
		$params=array(
			'qlty_project_id'=>$pid,
			'apply_funds'=>$fund
		);
		$result=$edudata->update_qlty_project($params);
		//$result=$edudata->update_project_fund($pid,$fund);
		if($result[0]['qlty_project_id']>0)
			return ajax_echo("经费修改成功");
		else
			return ajax_echo("发生错误，修改经费失败");

	}

	public function doupdate_project_status()
	{
		if(!is_admin())
			die("IS NOT A administrator!");
		$pid=z(t(v('pid')));
		$status=z(t(v('status')));
		if($pid==""||!is_numeric($pid))
		{
			return ajax_echo("pid丢失！");
		}
		if($status==""||is_null($status)) return ajax_echo("项目状态不能为空！");

		$edudata=self::getEdudataInstance();
		$params=array(
			'qlty_project_id'=>$pid,
			'status'=>$status
		);
		$result=$edudata->update_qlty_project($params);
		if($result[0]['qlty_project_id']>0)
			return ajax_echo("状态修改成功");
		else
			return ajax_echo("发生错误，修改失败");
	}

	public function ajax_update_director()
	{
		if(!is_admin())
			die("IS NOT A administrator!");
		$tid=z(t(v('tid')));
		if($tid==""||!is_numeric($tid))
		{
			return ajax_echo("tid丢失！");
		}
		$data['tid']=$tid;
		render($data,'ajax');
	}

	public function doupdate_project_director()
	{
		if(!is_admin())
			die("IS NOT A administrator!");
		$tid=z(t(v('tid')));
		$email=z(t(v('email')));
		if($tid==""||!is_numeric($tid))
		{
			return ajax_echo("tid丢失！");
		}
		if($email==""||is_null($email)) return ajax_echo("项目状态不能为空！");

		$edudata=self::getEdudataInstance();
		$params=array(
			'teacher_id'=>$tid,
			'email'=>$email
		);
		$result=$edudata->update_odp_teacher($params);
		if($result[0]['teacher_id']>0)
			return ajax_echo("负责人信息成功");
		else
			return ajax_echo("发生错误，修改失败");
	}


	public function department_trial()
	{
		/*
		*权限，is_department_leader()
		*/
		if(!is_department_leader())
			die("IS NOT Department Leader!");

		$type=z(t(v('type')));

		$department_leader=$_SESSION['teacher'];
		//var_dump($department_leader);
		$qlty_current_stage=unserialize(ss('qlty_current_stage'));
		$department_id=$department_leader['department_id'];
		$edudata=self::getEdudataInstance();
		//applyfile状态为等待部门领导审核推荐的项目
		$status=$GLOBALS['project_status']['APPLYFILE'];
		$department_id=$_SESSION['teacher']['department_id'];
		$projects=$edudata->get_wait_for_trial_department_projects($status,$department_id);

		//已提交初审的项目
		$xmktrial_status=$GLOBALS['project_status']['WAITING_FOR_VERIFY'];
		$check_projects=$edudata->get_wait_for_trial_department_projects($xmktrial_status,$department_id);

		//获取剩余时间
		$time=time();
		$rest_time=0;
		if($qlty_current_stage[$type]['current_stage']=='10')
		{
			$stage_time=$qlty_current_stage[$type]['stages']['10'];
			if( $time>strtotime($stage_time['begin']) && $time<strtotime($stage_time['end']))
			{
				//结束后延长一天
				$rest_time=strtotime($stage_time['end'])+39600-$time;
			}else{
				$rest_time=((strtotime($stage_time['end'])+39600-$time)>0)?(strtotime($stage_time['end'])+39600-$time):0;
			}
		}

		$data['qlty_category']=(unserialize($_SESSION['qlty_course_category']))+(unserialize($_SESSION['qlty_project_category']))+(unserialize($_SESSION['qlty_team_category']));

		$data['department_id']=$department_leader['department_id'];
		$data['qlty_rank']=unserialize($_SESSION['qlty_rank']);
		$data['check_projects']=$check_projects;
		$data['type']=$type;
		$data['rest_time']=$rest_time;
		$data['projects']=$projects;
		$data['top_title']=$data['title']="院系项目初审";
		$data['css'][]="c3counter.css";
		$data['js'][]="c3counter/c3counter.js";
		//$data['js'][]="c3counter/counter.js";
		$data['customjs']="C3Counter('counter', { startTime :".$rest_time." });";
		render($data);
	}

	public function department_leader_submit()
	{
		if(!is_department_leader())
			die("IS NOT Department Leader!");
		$teacher_id=z(t(v('tid')));
		$qlty_project_id=z(t(v('pid')));

		$edudata = self::getEdudataInstance();
		//获取项目信息
		$project_detail=$edudata->get_project_detail_by_id($qlty_project_id,$teacher_id);
		//项目主持人信息
		$director_detail=$edudata->get_director_detail($teacher_id);

		//获取参与人信息
		$participants = $edudata->get_project_participants($qlty_project_id);
		
		//申报书doc与PDF(其他材料这个时候还未上传)
		$assets=$edudata->get_project_assets($qlty_project_id);
		//var_dump($assets);
		$data['qlty_category']=(unserialize($_SESSION['qlty_course_category']))+(unserialize($_SESSION['qlty_project_category']))+(unserialize($_SESSION['qlty_team_category']));

		$data['qlty_rank']=unserialize($_SESSION['qlty_rank']);
		$data['qlty_specity']=unserialize($_SESSION['qlty_specity']);
		$data['project_detail']=$project_detail;
		$data['director_detail']=$director_detail;
		$data['participants']=$participants;
		$data['assets']=$assets;
		$data['title']=$data['top_title']="项目科初审";
		render($data);
	}

	public function leadertrial_pass()
	{

		if(!is_department_leader())
			die("IS NOT Department Leader!");
		$email=z(t(v('email')));
		$teacher_name=z(t(v('tname')));
		$mobile_phone=z(t(v('phone')));
		$project_name=urldecode(z(t(v('project_name'))));
		$teacher_id=z(t(v('tid')));
		$project_id=z(t(v('pid')));
		$type=z(t(v('type')));

		$data['email']=$email;
		$data['teacher_name']=$teacher_name;
		$data['mobile_phone']=$mobile_phone;
		$data['project_name']=$project_name;
		$data['teacher_id']=$teacher_id;
		$data['project_id']=$project_id;
		$data['type']=$type;
		render($data,'ajax');

	}

	public function department_pass_message()
	{
		if(!is_department_leader())
			die("IS NOT Department Leader!");
		$email=z(t(v('email')));
		$teacher_name=z(t(v('teacher_name')));
		$mobile_phone=z(t(v('mobile_phone')));
		$project_name=z(t(v('project_name')));
		$teacher_id=z(t(v('tid')));
		$project_id=z(t(v('pid')));
		$type=z(t(v('type')));
		$send_sms=z(t(v('send_sms')));
		//var_dump($send_sms);
		//更新项目状态
		$edudata = self::getEdudataInstance();
		$result=$edudata->update_project_status($project_id,$teacher_id,$GLOBALS['project_status']['WAITING_FOR_VERIFY']);
		if($result[0]['qlty_project_id']>0){
			//email默认发送
			
			//组装Email
			$subject="您的项目已被部门审核通过";
			$content="尊敬的".$teacher_name."：<br><br>"
					."您的《".$project_name."》项目已被部门审核通过，并提交项目管理科初审。登陆质量工程信息系统查看更多信息（点击此链接<a href='http://zlgc.cqtbi.edu.cn/'>http://zlgc.cqtbi.edu.cn/</a>）。<br><br>"
					."此邮件由系统自动发出，请勿回复。如有疑问，欢迎咨询教务处项目科42861081";
			$return_result="";
			$send_email_result=send_mail( $email , $subject , $content );
			$mail_result=json_decode($send_email_result);
					//var_dump($result);
			if($mail_result->message=='success')
				$return_result="邮件发送成功";
			else
				$return_result="邮件发送失败";

			if($send_sms=="on")
			{
				$content="尊敬的".$teacher_name."您好，您的项目已通过部门审核并推荐，请您登陆质量工程信息系统查看。【质量工程网】";
				$send_sms_result=send_sms($mobile_phone,$content);
				//var_dump($send_sms_result);
				if($send_sms_result=="1")
					$return_result .="短信已发送成功<br>";
				else
					$return_result .="短信发送失败";
			}

			//var_dump($send_sms_result);
			return ajax_echo($return_result."<script>$('#pass_message_btn').attr('disabled','true');location='/?a=department_trial&type=".$type."'</script>");
			
		}else{
			$r=$edudata->update_project_apply_time($project_id,$teacher_id);
			return ajax_echo("项目状态更新失败");
		}
	}

	public function generate_pdf_summary()
	{
		if(!is_department_leader())
			die("IS NOT Department Leader!");
		$department_id=z(t(v('depid')));
		$type=z(t(v('type')));
		$cqdd=z(t(v('cqdd')));
		$se=z(t(v('se')));
		if($department_id=="" ||is_null($department_id))
			return ajax_echo("部门id丢失");
		if($type==""||is_null($type))
			return ajax_echo("类型丢失");
		if($cqdd==""||is_null($cqdd))
			return ajax_echo("cqdd标识码丢失");
		if($se=="" || is_null($se))
			return ajax_echo("se丢失");
		if(md5('depid'.$department_id.$type)==$se)
		{
			$xmktrial_status=$GLOBALS['project_status']['WAITING_FOR_VERIFY'];
			$edudata=self::getEdudataInstance();
			$department_id=$_SESSION['teacher']['department_id'];
			$submit_projects=$edudata->get_wait_for_trial_department_projects($xmktrial_status,$department_id);

			//获取参与人
			$projects=array();
			foreach($submit_projects as $project){
				$participants=Array();
				$participants = $edudata->get_project_participants($project['qlty_project_id']);

				$participants_str="";
				if($participants){
					foreach($participants as $r)
						$participants_str .=$r['teacher_name']." ";
				}
				$projects[]=$project+Array('participants'=>$participants_str);
			}



			$qlty_category=(unserialize($_SESSION['qlty_course_category']))+(unserialize($_SESSION['qlty_project_category']))+(unserialize($_SESSION['qlty_team_category']));
			$qlty_rank=unserialize($_SESSION['qlty_rank']);
			$qlty_specity=unserialize($_SESSION['qlty_specity']);


			require_once(AROOT . 'lib' .DS. 'html2pdf'.DS.'html2pdf.class.php');
		    ob_start();

		    include(AROOT.'lib'.DS.'html2pdf'.DS.'examples'.DS.'summary.php');
		    $content = ob_get_clean();

		    // convert

		    try
		    {
		        $html2pdf = new HTML2PDF('P', 'A4', 'en', true, 'UTF-8', 0);
		        $html2pdf->pdf->SetDisplayMode('fullpage');
		        //$html2pdf->pdf->SetFont('droidsansfallback', '', 20);
		        $html2pdf->SetDefaultFont('droidsansfallback');
		        $html2pdf->writeHTML($content);
		        /*
		        *Output默认生成的pdf在网站的根目录
		        *我将其移动到了/static/pdf/目录下并写入数据
		        *2013-12-03
		        */
		        $oldname='summary.pdf';
		        $html2pdf->Output($oldname,'D');
		        //file_pop_download($oldname);
				//move file to /static/pdf ,huangXiaodong,2013-12-03
/*		        if(file_exists($oldname))
		        {
		        	//$newname='static/pdf/'.date('YmdHis',time()).rand(1000,9999).'.pdf';
		        	$dir='static/pdf/'.date('Y',time()).'/'.date('m',time()).'/';
		        	$newname=$dir.date('YmdHis',time()).rand(1000,9999).'.pdf';
		        	//rename('ticket.pdf', $newname);
		        	$result=move_file($oldname,$dir,$newname);
		        	if($result){
		        		$edudata = self::getEdudataInstance();
		        		$result=$edudata->update_fund_ticket_url($fundid,$newname);
		        		if($result['fund_id']>0 && $project['director_id']==$_SESSION['teacher']['teacher_id']){
		        			//写入数据库成功！并且当前用户是项目主持人！提出下载！
							file_pop_download($newname);

						}
					}
		        }*/

		    }
		    catch(HTML2PDF_exception $e) {
		        var_dump($e);
		        exit;
		    }


		}else{
			die("Bad Request");
		}

	}

	public function tutorial()
	{
		$data['title']=$data['top_title']="项目申报操作视频";
		render($data);
	}

	public function user()
	{

		self::init_generaldata();
		$data['departments'] = $_SESSION['department'];
		$data['title']=$data['top_title']="个人信息";
		$data['teacher']=$_SESSION['teacher'];
		render($data);
	}

	public function update_teacher_info()
	{

		$school=z(t(v('school')));
		$department1=z(t(v('department1')));
		$department2=z(t(v('department2')));
		$staff_id=z(t(v('staff_id')));
		$professional_title=z(t(v('pro_title')));
		$mobile_phone=z(t(v('mobile_phone')));

		if($school=="" || is_null($school))
			return ajax_echo("请确定校内或分校");
		if($school==='1')
		{
			$is_inside_school=1;
			$department_id=$department1;
		}
		elseif($school==='2'){
			$is_inside_school=0;
			$department_id=$department2;
		}

		if($professional_title=="" || is_null($professional_title))
		{
			return ajax_echo("职称不能为空!");
		}
		if($mobile_phone=="" || is_null($mobile_phone))
			return ajax_echo("手机号码不能为空");
		if(!preg_match("/^13[0-9]{1}[0-9]{8}$|15[0-9]{1}[0-9]{8}$|18[0-9]{1}[0-9]{8}$/",$mobile_phone))
			return ajax_echo("手机号码无效！");

		$teacher_id=$_SESSION['teacher']['teacher_id'];
		$edudata=self::getEdudataInstance();
		$result=$edudata->update_teacher_info($teacher_id,$is_inside_school,$department_id,$staff_id,$professional_title,encrypt($mobile_phone,c('key')));
		if($result['teacher_id']>0)
		{
			return info_page("个人信息修改成功！正在注销……请重新登陆<script>location='/?a=logout'</script>");
		}
	}

	public function ajax_update_project_name()
	{
		if(!is_admin())
			die("IS NOT A administrator!");
		$pid=z(t(v('pid')));
		if($pid=="" || is_null($pid)){
			return ajax_echo("pid不能为空");
		}

		$data['pid']=$pid;
		render($data,'ajax');
	}

	public function doupdate_project_name()
	{
		if(!is_admin())
			die("IS NOT A administrator!");
		$pname=z(t(v('pname')));
		$pid=z(t(v('pid')));

		if($pname=="" || is_null($pname))
			return ajax_echo("请输入新的项目名称");
		if($pid=="" || is_null($pid))
			return ajax_echo("pid不能为空");
		$edudata=self::getEdudataInstance();

		$params=array('qlty_project_id'=>$pid,'name'=>$pname);
		$result=$edudata->update_project_attr($params);
		if($result['qlty_project_id']>0)
			return ajax_echo("项目名称更新成功！");

	}

	public function ajax_update_project_rank_category()
	{
		if(!is_admin())
			die("IS NOT A administrator!");
		$pid=z(t(v('pid')));

		if($pid=="" || is_null($pid))
			return ajax_echo("pid不能为空");


		$edudata=self::getEdudataInstance();
		$project=$edudata->get_project_detail_with_project_id($pid);

		$data['qlty_category']=(unserialize($_SESSION['qlty_course_category']))+(unserialize($_SESSION['qlty_project_category']))+(unserialize($_SESSION['qlty_team_category']));
		$data['qlty_specity']=unserialize($_SESSION['qlty_specity']);
		$data['qlty_rank']=unserialize($_SESSION['qlty_rank']);
		$data['pid']=$pid;
		$data['project']=$project;
		render($data,'ajax');
	}

	public function doupdate_project_rank()
	{
		if(!is_admin())
			die("IS NOT A administrator!");
		$pid=z(t(v('pid')));
		if($pid=="" || is_null($pid))
			return ajax_echo("pid不能为空!");
		$category=z(t(v("category")));
		$belong_cqdd=z(t(v("belong_cqdd")));
		$rank=z(t(v("rank")));
		$specialty=z(t(v("specialty")));

		$params=Array(
				'qlty_project_id'=>$pid,
				'category'=>$category,
				'belong_cqdd'=>$belong_cqdd,
				'rank'=>$rank,
				'belong_specialty'=>$specialty
			);
		$edudata=self::getEdudataInstance();
		$result=$edudata->update_project_attr($params);
		if($result['qlty_project_id']>0)
			return ajax_echo("项目信息更新成功！");

	}

	public function expert_summary()
	{
		if(!is_expert())
			die("You should be a Expert!");
		$review_id=z(t(v('revid')));
		$edudata=self::getEdudataInstance();
		$results=$edudata->get_rev_results_detail_with_expert_id($review_id,$_SESSION['teacher']['teacher_id']);

		//将结果转换为project=>Array(result)的形式
		$projects=array();
		$projects_score=array();
		$comment_nodes=array();
		$project_comments=array();
		foreach($results as $result)
		{
			$projects[$result['qlty_project_id']][]=$result;
			if(!Array_key_exists($result['qlty_project_id'],$projects_score))
			{
				$projects_score[$result['qlty_project_id']]=$result['point'];
			}else{
				$projects_score[$result['qlty_project_id']] +=$result['point'];
			}


			//主观意见的节点
			if(!Array_key_exists($result['node_id'],$comment_nodes) && $result['node_type'])
			{
				$comment_nodes[$result['node_id']]=Array(
					'node_id'=>$result['node_id'],
					'node_name'=>$result['node_name'],
					'node_description'=>$result['node_description']
					);
			}

			if($result['node_type'])
			{
				$project_comments[$result['qlty_project_id']][]=$result['comment'];
			}
		}
//var_dump($project_comments);


		$qlty_category=(unserialize($_SESSION['qlty_course_category']))+(unserialize($_SESSION['qlty_project_category']))+(unserialize($_SESSION['qlty_team_category']));
		$qlty_rank=unserialize($_SESSION['qlty_rank']);
		$qlty_specity=unserialize($_SESSION['qlty_specity']);


		require_once(AROOT . 'lib' .DS. 'html2pdf'.DS.'html2pdf.class.php');
		ob_start();

		include(AROOT.'lib'.DS.'html2pdf'.DS.'examples'.DS.'expert.php');
		$content = ob_get_clean();

		    // convert

		try
		{
			$html2pdf = new HTML2PDF('P', 'A4', 'en', true, 'UTF-8', 0);
			$html2pdf->pdf->SetDisplayMode('fullpage');
		        //$html2pdf->pdf->SetFont('droidsansfallback', '', 20);
			$html2pdf->SetDefaultFont('droidsansfallback');
			$html2pdf->writeHTML($content);

			$oldname='expert.pdf';
			$html2pdf->Output($oldname,'D');

		}
		catch(HTML2PDF_exception $e) {
			var_dump($e);
			exit;
		}


		var_dump($projects);
		var_dump($projects_score);
		//var_dump($results);
	}

	public function expert_course_summary()
	{
		if(!is_expert())
			die("You should be a Expert!");
		$review_id=z(t(v('revid')));
		$group_id =z(t(v('gid')));
		$edudata=self::getEdudataInstance();
		$results=$edudata->get_rev_results_detail_with_expert_id($review_id,$_SESSION['teacher']['teacher_id']);
		$projects=$edudata->get_projects_with_group_id($group_id);

		$comment_nodes=array();
		$suggestions = array();
		//用director_id来标示，因为pid合并为空了，系统中保证一个人只能申报一个项目进行评审
		$project_score_arr=array();
		foreach($results as $result)
		{

			if($result['node_type']=='0' )
			{
				if(!Array_key_exists($result['director_id'],$project_score_arr)){
					$project_score_arr[$result['director_id']]=($result['point']>0)?$result['point']:0;
				}else{
					$project_score_arr[$result['director_id']] +=($result['point']>0)?$result['point']:0;
				}
			}else{
				$suggestions[$result['director_id']][$result['node_id']] = $result;
				if(!Array_key_exists($result['node_id'],$comment_nodes))
				{
					$comment_nodes[$result['node_id']]=$result['node_name'];
				}

			}

		}
		// var_dump($comment_nodes);exit();
				//将projects数组组成pid为key的数组，便于按分数排序输出
		$ids_projects = array();
		foreach ($projects as $project) {
			$ids_projects[$project['director_id']]=$project;
		}

				//按照分数排序
		arsort($project_score_arr);
				//通过与暂缓的分隔线，70
		$past_point =70;


//var_dump($project_comments);


		$qlty_category=(unserialize($_SESSION['qlty_course_category']))+(unserialize($_SESSION['qlty_project_category']))+(unserialize($_SESSION['qlty_team_category']));
		$qlty_rank=unserialize($_SESSION['qlty_rank']);
		$qlty_specity=unserialize($_SESSION['qlty_specity']);


		require_once(AROOT . 'lib' .DS. 'html2pdf'.DS.'html2pdf.class.php');
		ob_start();

		include(AROOT.'lib'.DS.'html2pdf'.DS.'examples'.DS.'expert_course.php');
		$content = ob_get_clean();

		    // convert

		try
		{
			$html2pdf = new HTML2PDF('P', 'A4', 'en', true, 'UTF-8', 0);
			$html2pdf->pdf->SetDisplayMode('fullpage');
		        //$html2pdf->pdf->SetFont('droidsansfallback', '', 20);
			$html2pdf->SetDefaultFont('droidsansfallback');
			$html2pdf->writeHTML($content);

			$oldname='expert.pdf';
			$html2pdf->Output($oldname,'D');

		}
		catch(HTML2PDF_exception $e) {
			var_dump($e);
			exit;
		}
	}

	public function admin_teachers()
	{
		if(!is_admin())
			die("NOT administrator!");

		$edudata=self::getEdudataInstance();
		$teachers=$edudata->get_all_teachers_detail();
		//var_dump($teachers);
		$dept_arr=$_SESSION['department'];
		$department=array();
		foreach ($dept_arr as $dept) {
			$department[$dept['department_id']]=$dept['department_name'];
		}
		$data['department']=$department;
		$data['teachers']=$teachers;
		$data['title']=$data['top_title']="全部教师数据";
		$data['js'][]="jquery.dataTables.min.js";
		$data['js'][]="pdata.js";
		$data['css'][]="jquery.dataTables.css";
		//$data['js'][]="bootstrap-dropdown.js";
		render($data);
	}

	public function ajax_admin_files()
	{
		if(!is_admin())
			die("NOT administrator!");
		$pid=z(t(v('pid')));
		if($pid==""||is_null($pid))
			return ajax_echo("pid丢失!");
		$edudata=self::getEdudataInstance();
		$assets=$edudata->get_project_assets($pid);
		$data['assets']=$assets;
		render($data,'ajax');

	}

	public function sms()
	{
		//仅用来测试
		$mobile_phone="13637977217";
		$content="尊敬的评审专家您好，您评审项目没有全部完成，请您访问质量工程信息系统在04-28 14:59前完成评审。谢谢！【质量工程网】";
		$send_sms_result=send_sms($mobile_phone,$content);
		var_dump($send_sms_result);
		if($send_sms_result=='1')
			$result .="Success<br>";
		else
			$result .="ERROR";
	}

	public function check_files()
	{
		if(!is_admin())
			die("IS NOT A administrator!");
		$edudata=self::getEdudataInstance();
		$projects=$edudata->get_all_projects_detail();
		$all_assets=$edudata->get_all_projects_assets();

		$assets=array();
		foreach ($all_assets as $asset) {
			$assets[$asset['qlty_project_id']][$asset['asset_type']]=Array(
					'asset_name'=>$asset['asset_name'],
					'asset_uri'=>$asset['asset_uri']
					);		
		}
		$data['qlty_category']=(unserialize($_SESSION['qlty_course_category']))+(unserialize($_SESSION['qlty_project_category']))+(unserialize($_SESSION['qlty_team_category']));

		$data['qlty_rank']=unserialize($_SESSION['qlty_rank']);
		$data['qlty_asset_type']=unserialize($_SESSION['qlty_asset_type']);
		$data['projects']=$projects;
		$data['assets']=$assets;
		$data['status_meaning']=array_flip($GLOBALS['project_status']);
		$data['title']=$data['top_title']="质量工程数据勘误修改";
		$data['js'][]="jquery.dataTables.min.js";
		$data['js'][]="pdata.js";
		$data['css'][]="jquery.dataTables.css";
		//$data['js'][]="bootstrap-dropdown.js";
		render($data);
	}

	public function allProjects(){
		if(!is_admin())
			die("NOT administrator!");
		$edudata=self::getEdudataInstance();
		$projects=$edudata->get_all_projects_detail();

		$qlty_category=(unserialize($_SESSION['qlty_course_category']))+(unserialize($_SESSION['qlty_project_category']))+(unserialize($_SESSION['qlty_team_category']));
		$dept_arr=$_SESSION['department'];
		$department=array();
		foreach ($dept_arr as $dept) {
			$department[$dept['department_id']]=$dept['department_name'];
		}
		$qlty_rank=unserialize($_SESSION['qlty_rank']);
		$qlty_specity=unserialize($_SESSION['qlty_specity']);
		$status_meaning=array_flip($GLOBALS['project_status']);

		//显示语义
		$sex_arr = array("男","女");
		$inside_school = array("电大分校或工作站","校内","校外或企业");
		$import_arr = array("系统申报","导入");
		$type_arr = array('xm'=>"教改项目",'kc'=>"课程项目",'tm'=>"教学团队");
		$cqdd_arr  = array('高职',"电大");
		$all_projects = array();
		foreach ($projects as $p) {
			$all_projects[] = array_merge($p,array(
					'department_id'=>$department[$p['department_id']],
					'teacher_pwd'=>'',
					'teacher_sex'=>$sex_arr[$p['teacher_sex']],
					'is_inside_school'=>$inside_school[$p['is_inside_school']],
					'mobile_phone'=>decrypt($p['mobile_phone'],c('key')),
					'is_imported'=>$import_arr[$p['is_imported']],
					'type'=>$type_arr[$p['type']],
					'category'=>$qlty_category[$p['category']],
					'rank'=>$qlty_rank[$p['rank']],
					'belong_cqdd'=>$cqdd_arr[$p['belong_cqdd']],
					'belong_specialty'=>$qlty_specity[$p['belong_specialty']],
					'created_time'=>($p['created_time']==0)?0:date('Y-m-d',$p['created_time']),
					'apply_time'=>($p['apply_time']==0)?0:date('Y-m-d',$p['apply_time']),
					'established_time'=>($p['established_time']==0)?0:date('Y-m-d',$p['established_time']),
					'change_time'=>($p['change_time']==0)?0:date('Y-m-d',$p['change_time']),
					'middle_time'=>($p['middle_time']==0)?0:date('Y-m-d',$p['middle_time']),
					'done_time'=>($p['done_time']==0)?0:date('Y-m-d',$p['done_time']),
					'NO'=>IS_NULL($P['NO'])?"空":$p['NO'],
					'status'=>$status_meaning[$p['status']]
				
				));
		}

		// var_dump($all_projects);exit();
		header('Content-type: application/json');
		die( json_encode( $all_projects ) );
	}
//default class End-->
}
